Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need help here with powershell, as im not that good in, im only starting, but i need already to make a powershell script but will run thru all collaborative spaces and modify 4 groups by setting different group owners.

Here is what i have:

function RetrieveSites()
{
    $cs = Get-CsWebAppUrl
    Get-SPSite -WebApplication $cs -Limit All | % {
        Write-host "Retrieving $($Site.Url)"
        ModifyGroupOwners -Site $_
    } 
}

function ModifyGroupOwners([Microsoft.SharePoint.SPSite] $Site)
{
    $spgroup = Get-SPGroup -Site $site -Limit All | % {
        if((spgroup.name -eq "Approver") -or ($spgroup.name -eq "Designer") -or ($spgroup.name -eq "Hierarchy Managers") -or ($spgroup.name -eq "Style Resource Readers") -or ($spgroup.name -eq "Restricted readers"))
        {
            $owner=$spgroup.name + " Managers"
            $spgroup.owner=$spgroup[$owner]
            $spgroup.update
            Write-host "$($spgroup.name) was updated"
        }
    }
}

function Get-CsWebAppUrl()
{
    $Farm = (Get-SPFarm)
    $CsWebAppUrl = $farm.Properties[$global:CsKey]
    if ([string]::IsNullOrEmpty($CsWebAppUrl))
    {
        write-error "Unable to find group Url, please check the portal map configuration"
        exit 1
    }
    return $CsWebAppUrl
}

So the big problem is for retrieving the groups and modifying them, i wrote some ps code but im not sure and i want to have some help and guidance.

Thanks alot for help in advance.

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

This little and simple script will go through all site collections on all web application and set group owner for desired groups:

Add-PsSnapin Microsoft.SharePoint.PowerShell

$groupNames = @("Approver", "Designer", "Hierarchy Managers", 
                    "Style Resource Readers", "Restricted readers" )
$ownerUsername = "UserName"

$webApps = Get-SPWebApplication 
foreach ($webApp in $webApps) {
  $web = Get-SPWeb $webApp.Url 
  $spuser = $web.EnsureUser($ownerUsername)

  foreach ($groupName in $groupNames) {
      $group = $web.SiteGroups[$groupName]
      $group.Owner = $spuser
      $group.Update()
  }
}

I hope this is what are you looking for. And keep in mind this is just example, some logging and error handling would be useful.

Edited

To search only one site collection:

  ....

  $web = Get-SPWeb "http://mycoolsite/"
  $spuser = $web.EnsureUser($ownerUsername)

  foreach ($groupName in $groupNames) {
      $group = $web.SiteGroups[$groupName]
      $group.Owner = $spuser
      $group.Update()
  }
share|improve this answer
    
It is really cool example, but i dont need to cycle thru all the web application only one as i know of and there yes i need to iterate thru sites to adjust the owner of particular groups. But the owner should be the group that exists and the name of that group is mostly the name of the collaborative space + 'managers' –  Igorok Jan 25 '12 at 22:13
    
mostly? is there any other condition that determines exact SiteGoup that needs to be modified? –  Vedran Rasol Jan 26 '12 at 10:46
    
thx for the help, it works –  Igorok Jan 26 '12 at 20:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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