SharePoint Online: Delete Unique Permissions in a Subsite using PowerShell

Requirement: Delete Unique Permissions of a Subsite in SharePoint Online using PowerShell

How to Remove Unique Permissions of a SharePoint Online Site?

Removing unique permissions and restoring permission inheritance for a subsite allows its security to be managed at the parent site level instead of managing the security separately from that subsite. To restore permission inheritance for a subsite in SharePoint Online, do the following:

  • Login to SharePoint Online, Navigate to the Subsite that you want to remove unique permissions.
  • Go to Settings >> Site Settings >> Click on “Site Permissions” link.
  • On the ribbon, click on the Permissions tab, and then, in the Inheritance group, click on Delete Unique Permissions. Confirm the prompt with OK.
    delete subsite unique permissions sharepoint online powershell

This removes unique permissions from the SharePoint Online subsite.

Delete Unique Permissions of a Subsite in SharePoint Online using PowerShell

Here is how to remove unique permissions in SharePoint Online subsite with PowerShell:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#To call a non-generic Load Method
Function Invoke-LoadMethod() {
            [Microsoft.SharePoint.Client.ClientObject]$Object = $(throw "Please provide a Client Object"),
   $Ctx = $Object.Context
   $Load = [Microsoft.SharePoint.Client.ClientContext].GetMethod("Load") 
   $Type = $Object.GetType()
   $ClientLoad = $Load.MakeGenericMethod($Type)
   $Parameter = [System.Linq.Expressions.Expression]::Parameter(($Type), $Type.Name)
   $Expression = [System.Linq.Expressions.Expression]::Lambda([System.Linq.Expressions.Expression]::Convert([System.Linq.Expressions.Expression]::PropertyOrField($Parameter,$PropertyName),[System.Object] ), $($Parameter))
   $ExpressionArray = [System.Array]::CreateInstance($Expression.GetType(), 1)
   $ExpressionArray.SetValue($Expression, 0)

#Config Parameters
$SiteURL= ""

#Get Credentials to connect
$Cred = Get-Credential

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
    #Get the Web
    $Web = $Ctx.Web

    #Check if the given subsite is using unique permissions
    Invoke-LoadMethod -Object $Web -PropertyName "HasUniqueRoleAssignments"

    #Reset broken inheritance
        #delete unique permissions of a subsite in sharepoint online powershell
        Write-host -f Green "Unique Permissions Removed from the Site!"
        Write-host -f Yellow "Site is Already Inheriting Permissions from the Parent!"
Catch {
    write-host -f Red "Error:" $_.Exception.Message

PnP PowerShell to Reset Permissions Inheritance in SharePoint Online Subsite

Let’s see how to reset subsite permissions in SharePoint Online using PnP PowerShell. This procedure will restore permissions of a subsite with the same permission as its parent site.

#Config Variables
$SiteURL = ""
#Connect PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Get the web
$Web = Get-PnPWeb

#Remove unique permissions

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published.