SharePoint Online: Delete Permission Level using PowerShell

Requirement: SharePoint Online Remove permission level using PowerShell

Warning: Never delete any OOTB default permission levels in SharePoint!

How to Delete Existing Permission Levels in SharePoint Online?

To delete an existing permission level, in SharePoint Online, follow these steps:

  1. Navigate to SharePoint Online Site collection where you want the permission level to be deleted.  (Make sure you are on the root web!)
  2. Click on Settings gear >> Select Site Settings from the Settings menu.
  3. On the Site Settings page, click on the “Site Permissions” link under the “Users and Permissions” section.
  4. On the Permissions page, click on the “Permission Levels” button from the Permissions tab of the ribbon. 
  5. On the Permission Levels page, Tick the check the box(es) for permission levels you want to delete, and click the “Delete Selected Permission Levels” link.
  6. Confirm the prompt with the OK button.
    sharepoint online delete permission level

This deletes the permission level in SharePoint Online!

PowerShell to Remove Permission Level in SharePoint Online:

#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"

#Parameters
$SiteURL = "https://crescenttech.sharepoint.com"
$PermissionLevelName ="Contribute Without Delete"

#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

    #Get the Permission Level and Delete
    $RoleDefinition = $Web.RoleDefinitions.GetByName($PermissionLevelName)
    $RoleDefinition.DeleteObject()
    $Ctx.ExecuteQuery()
 
    Write-Host -f Green "Permission Level Deleted Successfully!"
    }
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}

SharePoint Online: PnP PowerShell to Delete Permission Level

Here is how to remove permission level in SharePoint Online with PnP PowerShell

#Set Variables
$SiteURL = "https://crescent.sharepoint.com/sites/Marketing"

#Connect to PNP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get a Permission level
$PermissionLevel = Get-PnPRoleDefinition -Identity "Contribute Without Delete"

If($PermissionLevel -ne $Null)
{
    Remove-PnPRoleDefinition -Identity $PermissionLevel -Force
    Write-host -f Green "Permission Level Removed Successfully!"
}

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply