SharePoint 2013: Delete a custom permissions using PowerShell
$spSite = Get-SPSite "http://sedwdevrtm:432/sites/com"[xml]$file = Get-Content "C:\Users\Administrator\Desktop\XML\XmlSitePermissions.xml"$Permissionname = $file.sites.site.sitepermission $spWeb = $spSite | Get-SPWeb # we add a new Permission Level name "DotcomReadonly" to the site, which will allow users to only add new items (no editing or removing) # check to see if the permission your are going to add is already existing.. if null proceedforeach ($Permission in $Permissionname){Write-Host ($Permission) if($spWeb.RoleDefinitions[$Permission] -ne $null) { write-Host ($spWeb.RoleDefinitions.Name[$Permission]) -BackgroundColor DarkGreen $spRoleDefinition = New-Object Microsoft.SharePoint.SPRoleDefinition $spRoleDefinition.Name = $Permission $spWeb.RoleDefinitions.Delete($spRoleDefinition.Name) Write-Host $spRoleDefinition.Name " Deleted successfully" -BackgroundColor Gray } else { Write-Host "Custom Permission doesn't exist" }}$spWeb.Dispose()$spSite.Dispose()
Previous article xml can be used to delete or use for loop to compare and delete the permissions:
< sites >
< site >
< sitepermission >DotcomReadonly</ sitepermission >
< sitepermission >DotcomContribute</ sitepermission >
< sitepermission >DotcomSiteAdministrator</ sitepermission >
</ site >
< Permission >
< Permissions >ViewListItems,AddListItems,Open,ViewPages</ Permissions >
< Permissions >ViewListItems,AddListItems,OpenItems,Open,ViewPages</ Permissions >
< Permissions >ManageLists</ Permissions >
</ Permission >
</ sites >