I need a script to get all the group owners of a site collection in Sharepoint Online.

Could you please help?

Thank you

  • What have you tried so far? This is a community for helping, not doing the job for you May 12 '17 at 7:30
  • $siteURL = "sitecollection.com" $x = Get-SPOSiteGroup -Site $siteURL foreach ($y in $x) { Write-Host $y.Title -ForegroundColor "Yellow" Get-SPOSiteGroup -Site $siteURL -Group $y.Title | Select-Object -ExpandProperty Users Write-Host }
    – Peter Smp
    May 12 '17 at 7:33
  • The script above is the one I'm using to get all the groups and members from a site collection. Now I would like to know how can I get the group owners of each grou please.
    – Peter Smp
    May 12 '17 at 7:37

You cann use the below CSOM Powershell script to fetch the site collection Groups Owners. Save the below code in .ps1 file.

make sure you have Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll keep this dlls in a location where you saved the .ps1 file.

You have to enter site collection url, username, password in script.

#Add - PSSnapin Microsoft.SharePoint.PowerShell  

$host.Runspace.ThreadOptions = "ReuseThread" 

Function Get-SiteGroup-Owners 
    param ($sCSOMPath,$sSiteUrl,$sUserName,$sPassword,$FileName) 
        $sCSOMRuntimePath=$sCSOMPath +  "\Microsoft.SharePoint.Client.Runtime.dll"         
        $sCSOMPathdll=$sCSOMPath +  "\Microsoft.SharePoint.Client.dll"              
        Add-Type -Path $sCSOMPathdll          
        Add-Type -Path $sCSOMRuntimePath        

        #SPO Client Object Model Context 
        $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteUrl) 
        $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUserName, $sPassword)   
        #$spoCredentials = New-Object System.Net.NetworkCredential($sUserName, $sPassword)    # for on premise
        $spoCtx.Credentials = $spoCredentials        

        $web = $spoCtx.Web
        $spGroups =$web.SiteGroups


        Write-Host "Groups Count= $($spGroups.Count)"

        foreach($spGroup in $spGroups)
            $site = New-Object -TypeName PSObject -Property @{
                                SiteUrl =$sSiteUrl
                                GroupName = $spGroup.Title
                                GroupOwner = $spGroup.OwnerTitle

                                } | Select  SiteUrl,GroupName,GroupOwner

          $site| Export-CSV ($sCSOMPath+"\"+$FileName+".csv") -NoTypeInformation -Append #-Encoding UTF8

        Read-Host -Prompt "file created Successfull..! in the following path $sCSOMPath, Press any key to close this window"

    catch [System.Exception] 
        Write-Host -ForegroundColor Red $_.Exception.ToString()    
        Read-Host -Prompt "Operation failed..! Press any key to close this and re run the script"

$FileName= "SiteCollection_GroupOwners"          
$sSiteUrl = "Site Collection Url"  
$sUserName = "Enter User" 
$sPassword = ConvertTo-SecureString "Password" -AsPlainText -Force 

$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath

Write-Host "Getting Site Collection group Owners"
Write-Host "-----------------------------------" 
Get-SiteGroup-Owners -sCSOMPath $dir -sSiteUrl $sSiteUrl -sUserName $sUserName -sPassword $sPassword  -FileName $FileName 
  • Hello Suresh Bolineni, Many thanks for this! Is that a way to adjust the script in order to get all the members of each group as well? Thanks again!
    – Peter Smp
    May 12 '17 at 10:12
  • Hi Peter smp..!. Yes you can get the list of all users from the group. You can give vote and select this an answer for this question. you raise one more question to get the users. I will Answer for you. May 12 '17 at 10:12
  • I've marked as an answer and I already voted. Many thanks. I'm going to make the question again. As requested, Is that a way to adjust the script in order to get all the members of each group as well? Thanks again!
    – Peter Smp
    May 12 '17 at 10:37
  • Okay sure. Why I asked to do like this is other people also might search for getting group owners through script. If I modify this existing script. the answer is irrelevant for the question :) May 12 '17 at 10:44
  • Have raised the question ? May 12 '17 at 10:51

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.