Forum Discussion

RichardS's avatar
RichardS
Copper Contributor
Aug 04, 2023
Solved

403 with a ctx.load($WEB) executeQuery

I have a powershell script which is failing with a 403 Forbidden.  I have tried 2 variants of Connect-PnPOnline    $SiteURL = “https://MyDomain.sharepoint.com/sites/MySPSite/” Connect-PnPOnline -U...
  • SvenSieverding's avatar
    Aug 04, 2023

    Hi RichardS ,

    If you want to use the authentication provided by PnP Powershell, then you need to get the context using the "Get-PnPContext" command

    $Ctx=Get-PnPContext
    $Web = $Ctx.Web
    $Ctx.Load($Web)
    $Ctx.Load($Web.AllProperties)
    $Ctx.ExecuteQuery()


    If you call 

    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) 

    you create a context object that has not yet been authenticated.

    Best Regards,
    Sven

Resources