Tuesday 31 December 2013

Add Custom Permission Levels using PowerShell


Add Custom Permission Levels using PowerShell 


$spSite = Get-SPSite "http://abc/sites/xyz"
  
$spWeb = $spSite | Get-SPWeb

# we add a new Permission Level name "MyCustomPermission" 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 proceed

if($spWeb.RoleDefinitions["MyCustomPermission"] -eq $null)
{
    $spRoleDefinition = New-Object Microsoft.SharePoint.SPRoleDefinition
    $spRoleDefinition.Name = "MyCustomPermission"
    $spRoleDefinition.Description = "Can only Add items"
    $spRoleDefinition.BasePermissions = "ViewListItems, AddListItems, Open, ViewPages"
    $spWeb.RoleDefinitions.Add($spRoleDefinition)
}

$spWeb.Dispose()

$spSite.Dispose()



Note : Below command will list , all the base permissions options in the 


[System.Enum]::GetNames("Microsoft.SharePoint.SPBasePermissions")




No comments:

Post a Comment