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 in the root web!)
  2. Click on Settings gear >> Select Site Settings from the Settings menu.
  3. On the Site Settings page, Click on "Site Permissions" link under Users and Permissions section.
  4. On the Permissions page, Click on "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 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"

$SiteURL = ""
$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)
    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 = ""

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

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.