0

I am trying to run the code below to update the "noCrawl" property but I am facing an issue with Invoke-PnPQuery:

Connect-PnPOnline -Url $url -Credentials $cred
$Web = Get-PnPWeb
$Web.NoCrawl = $true
$Web.Update()
Invoke-PnPQuery

I get the following error

Invoke-PnPQuery : Access denied. You do not have permission to perform this action or access this resource. Au caractère Ligne:2 : 13 Invoke-PnPQuery CategoryInfo : NotSpecified: (:) [Invoke-PnPQuery], ServerUnauthorizedAccessException FullyQualifiedErrorId : Microsoft.SharePoint.Client.ServerUnauthorizedAccessException,PnP.PowerShell.Commands.Base.InvokeQuery

Seems like a permissions issue, but i'm struggling with it.

Can someone help please?

2
  • Your code worked for me, so you definitely have some permission issue. Can you manually set it by going to Site Settings-> Search and offline availability -> and set "No" for Allow this site to appear in search results – Matiur Rahman Nov 10 '20 at 20:43
  • Try switching to another site collection administrator account and run the command again. Run the upgrade command “Update-Module SharePointPnPPowerShell*” if necessary. – Chelsea_MSFT Nov 11 '20 at 7:57
0

I finally figure it out.

To perform an action like to upadate "nocrawl" property, you need to have another property of the web "-DenyAndAddCustomizePages" switched to false:

Connect-PnPOnline -Url $adminURL -Credentials $cred
Set-PnPSite -Identity $url -DenyAndAddCustomizePages $false

Then the code can be executed without any problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.