Update SharePoint Group Owner using Powershell for SharePoint 2007

I'm trying to write a script that iterates through all Site Collection SharePoint groups and updates the Group Owner.  I'm able to traverse the various SharePoint Groups and retrieve the existing Group Owners, but my code doesn't actually update the Group Owner.  The following is my code:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$site = New-Object Microsoft.SharePoint.SPSite("https://mysharepointsite/sites/sitename")
$web = $site.OpenWeb()
$groups = $web.sitegroups
$groupowner = "New Group Name"
foreach ($grp in $groups){
"Group: " + $grp.name
"Name:" + $grp.Owner.Name
 $grp.Owner.Name = $groupowner
$grp.Update()
 }
$web.Update()
$site.Dispose()
peerlesslvAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

prashanthdCommented:
The following should be helpful..
param([string]$url, [string]$Group, [string]$Role, [string]$Owner, [switch]$help)

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

function GetHelp() {


$HelpText = @"

DESCRIPTION:
NAME: Add-SPGroup
Adds a New SharePoint Group

PARAMETERS: 
-url		Url to SharePoint Site
-Group		Name of New Group
-Role		Role Of New Group
-Owner		Group Owner

SYNTAX:

Add-SPGroup -url http://moss -Group "New Group" -Role Read -Owner "powershell\administrator"

Adds the Group "New Group" to the Site.

Add-SPSGroup -help

Displays the help topic for the script

"@
$HelpText

}

function Get-SPSite([string]$url) {

	New-Object Microsoft.SharePoint.SPSite($url)
}

function Get-SPWeb([string]$url) {

	$SPSite = Get-SPSite $url
	return $SPSite.OpenWeb()
	$SPSite.Dispose()
}

function Add-SPGroup ([string]$url, [string]$Group, [string]$Role, [string]$Owner) {

	$SPSite = Get-SPSite $url
	$OpenWeb = Get-SPWeb $url

	$OpenWeb.SiteGroups.Add($Group,$SPSite.RootWeb.AllUsers[$Owner], $Null, $Group)
	$CurrentGroup = $OpenWeb.SiteGroups[$Group]
	$OpenWeb.Roles[$Role].AddGroup($CurrentGroup)

	$OpenWeb.Dispose()
}
if($help) { GetHelp; Continue }
if($url -AND $Group -AND $Role -AND $Owner) { Add-SPGroup -url $url -Group $Group -Role $Role -Owner $Owner }

Open in new window

0
peerlesslvAuthor Commented:
Thanks for the response.  Looks like the code you provided is used for adding new groups.  In my situation, I'm trying to iterate all SharePoint Groups within my site and set the owner to an existing SharePoint Group within the site.  I did try to leverage some of your code and came up with the following.  

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$site = New-Object Microsoft.SharePoint.SPSite("https://mysharepointsite/sites/sitename")
$web = $site.OpenWeb()

$groups = $web.sitegroups
$groupowner = $site.RootWeb.AllUsers["Existing SharePoint Group"];

foreach ($grp in $groups){
"Group: " + $grp.name
"Name:" + $grp.Owner.Name
 $grp.Owner.Name = $groupowner
$grp.Update()
 }

$web.Update()
$site.Dispose()

In doing so, I got the following error:
Exception setting "Name": "The parameter Name cannot be empty or bigger than 255 characters."

This tells me that this variable isn't getting set properly:
$groupowner = $site.RootWeb.AllUsers["Existing SharePoint Group"];

Any thoughts on what I could be doing wrong?


0
peerlesslvAuthor Commented:
Got it...turns out I can't set Group Owner with the following line:

$grp.Owner.Name = $groupowner

Instead, this worked:

$grp.Owner=$web.SiteGroups["Existing SharePoint Group"];
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
peerlesslvAuthor Commented:
I granted you the points.  While I didn't use any of your code, it got me to think that I couldn't assign a Group Owner a string, but rather a Site Group object.
0
prashanthdCommented:
Thanks!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SharePoint

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.