Today, I will explain you about How to Add Permission Levels Using Powershell in SharePoint 2013.Besides using PowerShell to switch or adding list permissions, you’ll additionally add new Permission Levels. As permission levels don’t persist within website templates, this will be handy once making deployment scripts for brand new sites.
Here’s however you do it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# Add Permission Level to a site $spSite = Get-SPSite "http://youwebsite.com" # We'll assume the list is in the top-level site in the site collection $spWeb = $spSite | Get-SPWeb # In this example, we add a new Permission Level labelled "Add Only" to the site, which will allow users to only add new items (no editing or removing) if($spWeb.RoleDefinitions["Add Only"] -eq $null) { # Role Definition named "Add Only" does not yet exist $spRoleDefinition = New-Object Microsoft.SharePoint.SPRoleDefinition $spRoleDefinition.Name = "Add Only" $spRoleDefinition.Description = "Can only Add items. Use this Permission Level for List or Library Permissions." # .Type is a ReadOnly property, hence it'll remain on "None". # Use the command [System.Enum]::GetNames("Microsoft.SharePoint.SPBasePermissions") to get a list of possible BasePermission values # For this Permission Level, we'll add four base permissions: $spRoleDefinition.BasePermissions = "ViewListItems, AddListItems, Open, ViewPages" $spWeb.RoleDefinitions.Add($spRoleDefinition) } #Display the properties for our new Permission level $spWeb.RoleDefinitions["Add Only"] | Out-Host $spWeb.Dispose() $spSite.Dispose() |
Unfortunately, the RoleDefinition.Type property, that contains a RoleType Enum value, is Read-Only. Hence, it’ll get the default value “None”.
The .BasePermissions Property could be a flags attribute that contains the particular permissions granted to users and groups assigned with the permission level. See MSDN for a description of those Permissions, or use the following command to enumerate them in PowerShell:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# Enumerate through SPBasePermissions PS > [System.Enum]::GetNames("Microsoft.SharePoint.SPBasePermissions") EmptyMask ViewListItems AddListItems EditListItems DeleteListItems ApproveItems OpenItems ViewVersions DeleteVersions CancelCheckout ManagePersonalViews ManageLists ViewFormPages Open ViewPages AddAndCustomizePages ApplyThemeAndBorder ApplyStyleSheets ViewUsageData CreateSSCSite ManageSubwebs CreateGroups ManagePermissions BrowseDirectories BrowseUserInfo AddDelPrivateWebParts UpdatePersonalWebParts ManageWeb UseClientIntegration UseRemoteAPIs ManageAlerts CreateAlerts EditMyUserInfo EnumeratePermissions FullMask |
SharePoint 2013 Hosting Recommendation
HostForLIFE.eu’s SharePoint 2013 Hosting solution offers a comprehensive feature set that is easy-to-use for new users, yet powerful enough for the most demanding web developer expert. Hosted SharePoint Foundation 2013 is the premiere web-based collaboration and productivity enhancement tool on the market today. With SharePoint 2013 Foundation, you can quickly access and manage documents and information anytime, anywhere though a Web browser in a secure and user friendly way. SharePoint hosting services start at only at €9.99/mo, allowing you to take advantage of the robust feature set for a small business price. HostForLIFE.eu offers a variety of hosted SharePoint Foundation 2013 plans as well as dedicated SharePoint 2013 Foundation options