0

I am using SharePoint Online, having 1200+ site in the organzation's default site collection companyname.sharepoint.com/sitenames.

All the current 1200+ sites are having a unique permission on site level as well as list and library level.

Now I am being asked that the permission on all site under this default site collection should be change back to Inherit from the parent site, but the unique permission on the content with in it should remain as is (unique permission on List/Lib)

can I get a PowerShell to achieve the same !

1

1 Answer 1

5

Please try the following code:

#Config Variables
$SiteURL = "https://domain.sharepoint.com/sites/sitename"

#Get Credentials to connect
$Cred = Get-Credential

Try {
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Cred

#Get subsites in SharePoint Online using PnP PowerShell
$WebsCollection = Get-PnPSubWeb -Recurse
 
#Iterate through each subsite
ForEach($Web in $WebsCollection)
{
    #Remove unique permissions
    $Web.ResetRoleInheritance()
    Invoke-PnPQuery
}
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
2
  • Have you tried the code? Is there any problem? Nov 23, 2022 at 6:01
  • Yes, it worked like charm. Thank you Amy
    – cjs
    Nov 23, 2022 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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