Wednesday, January 14, 2015

How to create sharepoint Group with read only permissions using powershell for entire site?

* Please update URL in script


$site = Get-SPSite -Identity "http://test"
$web =Get-SPWeb -Identity $site.RootWeb
$web =$site.OpenWeb()
$web.SiteGroups.Add(“$web ReadOnly”, $web.Site.Owner, $web.Site.Owner, “Use this group to grant people read permissions to the $web site”)
$visitorsGroup = $web.SiteGroups["$web ReadOnly"]
$visitorsGroup.AllowMembersEditMembership = $true
$visitorsGroup.Update()
$visitorsGroupAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($visitorsGroup)
$visitorsRoleDefinition = $web.Site.RootWeb.RoleDefinitions["Read"]
$visitorsGroupAssignment.RoleDefinitionBindings.Add($visitorsRoleDefinition)
$web.RoleAssignments.Add($visitorsGroupAssignment)
 $web.Update()
$web.Dispose()


Please follow below URL for .ps1 file

https://gallery.technet.microsoft.com/create-sharepoint-Group-3cefd0a7

No comments:

Post a Comment

Google+ Followers