Thursday, May 16, 2013

Add Users to SharePoint Group using PowerShell

$USER_TO_ADD = $null;
 $web = Get-SPWeb -Identity "http://yoursite.com"
$manageGroup = $web.SiteGroups["GroupName"]
 try {
 $adUsername = "$USER_TO_ADD";
 $spUser = $web.Site.RootWeb.EnsureUser($adUsername.Split('\',1));    $manageGroup.AddUser($spUser);
 $manageGroup.Update();
 write-host "User: "
 $spUser.Name "was added to group" }
 catch
 {
    $_ Write-Host $spUser " does not exists"
 }
 } $web.Update(); $web.Dispose();

No comments:

Post a Comment