Avatar of peerlesslv
peerlesslv

asked on 

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

Avatar of undefined
Last Comment
prashanthd
SOLUTION
Avatar of prashanthd
prashanthd
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of peerlesslv
peerlesslv

ASKER

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?


ASKER CERTIFIED SOLUTION
Avatar of peerlesslv
peerlesslv

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of peerlesslv
peerlesslv

ASKER

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.
Avatar of prashanthd
prashanthd
Flag of India image

Thanks!!
Microsoft SharePoint
Microsoft SharePoint

Microsoft Sharepoint is a software platform and family of software products used for collaboration and web publishing combined. These capabilities include developing web sites, portals, intranets, content management systems, search engines, wikis, blogs, and other tools for business intelligence and collaboration. SharePoint has a Microsoft Office-like interface, and it is closely integrated with the Office suite.

40K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo