Forum Discussion
RichardS
Aug 04, 2023Copper Contributor
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...
- 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
SvenSieverding
Aug 04, 2023Bronze Contributor
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
- RichardSAug 04, 2023Copper ContributorMany Thanks . That makes perfect sense