SharePoint Online: Delete Permission Level using Powershell
Requirement: SharePoint Online Remove permission level using PowerShell
How to Delete Existing Permission Levels in SharePoint Online?
To delete an existing permission level, in SharePoint Online, follow these steps:
PowerShell to Remove Permission Level in SharePoint Online:
SharePoint Online: PnP PowerShell to Delete Permission Level
Here is how to remove permission level in SharePoint Online with PnP 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:
- Navigate to SharePoint Online Site collection where you want the permission level to be deleted. (Make sure you are in the root web!)
- Click on Settings gear >> Select Site Settings from the Settings menu.
- On the Site Settings page, Click on "Site Permissions" link under Users and Permissions section.
- On the Permissions page, Click on "Permission Levels" button from the Permissions tab of the ribbon.
- 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.
- Confirm the prompt with OK button.
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!" }
No comments:
Please Login and comment to get your questions answered!