5

I have this PS script to change the group owner of a SharePoint group to a domain user. I would like to use this script to change it to an existing SharePoint group. The current script only allows for domain users....

Any ideas?

#Get the SPWeb
$web = Get-SPWeb "URL"

#Get the Group
$group = $web.SiteGroups["Group 1"]
$group = $web.SiteGroups["Group 2"]
#Get the User 
$user = $web.EnsureUser("domain\user")

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

#Update the Group
$group.Update()
5

You just need a small change to your PowerShell script.

$web = Get-SPWeb http://webUrl
$groupOwner = $web.SiteGroups["GroupA"] #this group will own "GroupB"
$groupTarget = $web.SiteGroups["GroupB"]
$groupTarget.Owner = $groupOwner
$groupTarget.Update()

For all groups in a web:

$web = Get-SPWeb http://webUrl
$groupName = "SharePoint Group Name" #this will be the owner
$groupOwner = $web.SiteGroups[$groupName]

foreach($group in ($web.SiteGroups | ?{$_.Name -ne $groupName}))
{
    $group.Owner = $groupOwner
    $group.Update()
}
  • OK new problem. I've used this code successfully but I know want to change the owner of more than one group so I re use the $groupTarget = $web.SiteGroups["GroupB"] so it reads $groupTarget = $web.SiteGroups["GroupC"] etc but it doesn't work. Any ideas? – Mike Blair Feb 11 '16 at 19:46
  • Groups can only be owned by a single object (User or Group). – Trevor Seward Feb 11 '16 at 19:59
  • So how can I use a script to set the owner for multiple sharepoint groups? – Mike Blair Feb 11 '16 at 22:29
  • 1
    See my updated answer. – Trevor Seward Feb 11 '16 at 22:37
  • 1
    Made a small mistake in my answer, missing a closing parenthesis. – Trevor Seward Feb 22 '16 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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