Sharepoint 2010 Grant Permission to a Group using Powershell
Sometimes we need to grant permission to a particular group. There are different different permission levels in sharepoint. Below are some examples:
Design, Contribute, Read, View Only
For allow group of user as per mentioned permission level here is a powershell script. I think this will be very helpful for grant permissions.
clear
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
Add-PSSnapin Microsoft.SharePoint.Powershell
$Url = "Sitecollection/Site Url on which we need to grant permissions"
$GroupName = "All Authenticated Users" #Group Name
$PermissionLevel = "Full Control" # Permission Level
$Description = "This group contains all authenticated users."
$web = Get-SPWeb -Identity $Url
if ($web.SiteGroups[$GroupName] -ne $null)
{
Write-Host "Group $GroupName already exists!" -foregroundcolor Red
}
else
{
$web.SiteGroups.Add($GroupName, $web.Site.Owner, $web.Site.Owner, $Description)
$group = $web.SiteGroups[$GroupName]
$roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($group)
$roleDefinition = $web.Site.RootWeb.RoleDefinitions[$PermissionLevel]
$roleAssignment.RoleDefinitionBindings.Add($roleDefinition)
$web.RoleAssignments.Add($roleAssignment)
$web.Update()
Write-Host "Group $GroupName created successfully" -foregroundcolor Green
}
$user = "c:0(.s|true"
# $web.SiteGroups[$GroupName].AddUser($user, "", "","")
Set-SPUser -Identity $user -web $Url -Group $GroupName
$web.Dispose()
Design, Contribute, Read, View Only
For allow group of user as per mentioned permission level here is a powershell script. I think this will be very helpful for grant permissions.
clear
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
Add-PSSnapin Microsoft.SharePoint.Powershell
$Url = "Sitecollection/Site Url on which we need to grant permissions"
$GroupName = "All Authenticated Users" #Group Name
$PermissionLevel = "Full Control" # Permission Level
$Description = "This group contains all authenticated users."
$web = Get-SPWeb -Identity $Url
if ($web.SiteGroups[$GroupName] -ne $null)
{
Write-Host "Group $GroupName already exists!" -foregroundcolor Red
}
else
{
$web.SiteGroups.Add($GroupName, $web.Site.Owner, $web.Site.Owner, $Description)
$group = $web.SiteGroups[$GroupName]
$roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($group)
$roleDefinition = $web.Site.RootWeb.RoleDefinitions[$PermissionLevel]
$roleAssignment.RoleDefinitionBindings.Add($roleDefinition)
$web.RoleAssignments.Add($roleAssignment)
$web.Update()
Write-Host "Group $GroupName created successfully" -foregroundcolor Green
}
$user = "c:0(.s|true"
# $web.SiteGroups[$GroupName].AddUser($user, "", "","")
Set-SPUser -Identity $user -web $Url -Group $GroupName
$web.Dispose()
Comments
Post a Comment