6

I have succesfully been able to create a SharePoint group and assign it an owner. But now I noticed that it only works if the group has not been created. So now I need to add a way to modify the existing group and change the owner. I haven't been succesfull in making it work. Hope some one can shed some light on it. Below is the script I used to create the groups. Thanks.

$SCurl = "http://google.com/sites/sas"

$GroupNamePrefix = "SAS"

$GroupOwner1 = "SharePoint Admins"

$GroupOwner2 = $GroupNamePrefix+" Security Admin"

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$SPSite = New-Object Microsoft.SharePoint.SPSite($SCurl)
$OpenWeb = $SPSite.OpenWeb() 

$OpenWeb.SiteGroups.Add($GroupNamePrefix+" Designers",$OpenWeb.SiteGroups[$GroupOwner1],$OpenWeb.SiteUsers[""],"Members of this group can edit lists, 
document libraries, and pages in the site. Designers can create Master Pages and Page Layouts in the Master Page Gallery and can change the behavior 
and appearance of each site in the site collection by using the master pages and CSS files.")


$OpenWeb.Update()
$OpenWeb.Dispose() 
$SPSite.Dispose()

1 Answer 1

7

Here you go. Should be pretty straightforward:

#Get the SPWeb
$web = Get-SPWeb http://url_to_web

#Get the Group
$group = $web.SiteGroups["Group Name"]

#Get the User 
$user = $web.EnsureUser("domain\username")

#Assign that user as the owner
$group.Owner = $user

#Update the Group
$group.Update()

EDIT Added @John Craven's suggestion

6
  • If the user doesn't exist in the group, you can get them from the $web object: $web.Users["domain\username"] Commented Jun 4, 2013 at 16:32
  • 1
    Or, even better, by doing $web.EnsureUser("domain\username"), which will add the user to the site if they aren't there already. Commented Jun 4, 2013 at 16:33
  • @JohnChapman Will this work if the Owner is also a SharePoint group. Sorry I left out that detail but the new onwer that I need to assign is a SharePoint group and not a single user. Commented Jun 4, 2013 at 18:01
  • Yes, you can assign a group as an Owner. And it can also be itself. For instance, $group.Owner = $group. Commented Jun 4, 2013 at 18:59
  • Great it worked. What if I wanted to assign the new owner to multiple groups? @JohnChapman Commented Jun 4, 2013 at 19:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.