SharePoint Online: Delete Permission Level using PowerShell

Requirement: SharePoint Online Remove permission level using PowerShell.

How to Delete a Permission Level in SharePoint Online?

Permission levels in SharePoint Online are sets of permissions that define what actions a user can perform in a site. It is important to manage permission levels in SharePoint to ensure that users have the correct level of access to perform their tasks. In some cases, you may need to delete a permission level that is no longer necessary. In this article, we will explore the steps required to delete a permission level in SharePoint Online.

Deleting a permission level is a great way to clean up your permissions structure If you no longer need a custom permission level. This blog post will show you how to delete a permission level in SharePoint Online.

Warning: Never delete any Out-of-the-box default permission levels in SharePoint!

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

  1. Navigate to the 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, you will see a list of all the permission levels defined for the site. Locate the permission level that you want to delete, Tick the checkbox(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:

Use this PowerShell script if you want to delete a custom permission level. Please note that deleting a permission level is easy, but it’s important to remember that this action cannot be undone!

#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://Crescent.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 a 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 -Interactive

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

If you want to create a new permission level, use: How do I create a permission level in SharePoint Online?

Conclusion

In conclusion, deleting a permission level in SharePoint Online is a straightforward process that can be accomplished in a few simple steps. By following these steps, you can effectively manage the permissions in your SharePoint Online site to ensure that users have the correct level of access. By keeping your permission levels up-to-date and organized, you can improve the overall security and efficiency of your SharePoint Online site. With the power of PowerShell, you can automate the process of deleting permission levels and make changes to your SharePoint environment more quickly and efficiently. With the scripts provided in this article, you can effectively delete permission levels in SharePoint Online using PowerShell and take control of your site’s security and organization.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *