Add/remove sharepoint group using power shell
July 27th, 2011- Posted By: Jonathan Adams
- 1 Comment
Add/remove sharepoint group using power shell
Content from http://vimleshtiwari.blogspot.com/2011/01/addremove-sharepoint-group-using-power.html
$member = $web.AllUsers[“domain\username”] $CustomPermission =”Permission Name”
$CustomRoleRoledef = New-Object “Microsoft.SharePoint.SPRoleDefinition”
$CustomRoleRoledef.Name = “$CustomPermission”
$CustomRoleRoledef.Description = “Custom permission level for Site Owners”
$CustomRoleRoledef.BasePermissions =
“CancelCheckout,AddListItems,EditListItems,DeleteListItems,ViewListItems,OpenItems,ViewVersions, DeleteVersions,CreateAlerts,ViewFormPages,ViewUsageData,ViewPages,BrowseUserInfo,ManageAlerts,
$web.RoleDefinitions.Add($CustomRoleRoledef)
$web.Update()
# Create custom group
$CustomGroup =”My Custom Group”
$web.SiteGroups.Add(“$CustomGroup”, $member, $null,”Custom Group “)
#Assign Permission to the Group
$customPermission = $web.RoleDefinitions[“$CustomRoleRoledef “]
# If you don’t want to use custom permission, you can directly give existing permission name i.e “Full Control/Contributor/Design/Visitor”
#$existingPermission = $web.RoleDefinitions[“Design”]
$customPermissionAssignment = New-Object “Microsoft.SharePoint.SPRoleAssignment” -ArgumentList $web.SiteGroups[“$CustomGroup”]
$customPermissionAssignment.RoleDefinitionBindings.Add($customPermission)
$web.RoleAssignments.Add($techAdminRoleAssignment)
#Remove a sharepoint group using power shell
#Remove Groups if already exist
$GroupName =”Custom Group”
$objSiteGroup = $web.SiteGroups[“$GroupName”]
if ($objSiteGroup)
{
$web.SiteGroups.Remove(“$GroupName”)
}
James
February 7, 2012 at 9:48PMHello;
Nice script but has a syntax problem.
There is no $techAdminRoleAssignment variable instantiated.
So you are passing nothing to the roleassignment in this call:
$web.RoleAssignments.Add($techAdminRoleAssignment)
-cheers