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()
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

  • If the user doesn't exist in the group, you can get them from the $web object: $web.Users["domain\username"] – John Chapman Jun 4 '13 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. – NotVonKaiser Jun 4 '13 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. – xIIx PEGA xIIx Jun 4 '13 at 18:01
  • Yes, you can assign a group as an Owner. And it can also be itself. For instance, $group.Owner = $group. – John Chapman Jun 4 '13 at 18:59
  • Great it worked. What if I wanted to assign the new owner to multiple groups? @JohnChapman – xIIx PEGA xIIx Jun 4 '13 at 19:14

protected by Community Apr 16 '18 at 8:53

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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