Skip to content

Instantly share code, notes, and snippets.

@vaderj
Last active June 12, 2018 16:55
Show Gist options
  • Save vaderj/4d3fc7cd2ae02797a47293f8f959306d to your computer and use it in GitHub Desktop.
Save vaderj/4d3fc7cd2ae02797a47293f8f959306d to your computer and use it in GitHub Desktop.
Add a user to a SharePoint site #PowerShell #SharePoint
$web = Get-SPWeb "http://portal"
function AddGroupToSite ($web, $groupName, $permLevel)
{
$account = $web.SiteGroups[$groupName]
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$role = $web.RoleDefinitions[$permLevel]
$assignment.RoleDefinitionBindings.Add($role);
$web.RoleAssignments.Add($assignment)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment