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 Answer 1


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
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
  • 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 you have read our privacy policy.

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