Find Office 365 Groups with a specific user as owner using PowerShell

 Office 365, Office 365 Groups, Raghuramji
Feb 10 2017

In this blog, we shall check how to get Office 365 Groups with specific user as owner. There are scenarios, where you need to identify the groups and transfer the ownership during employee off-boarding process. This PowerShell script is useful in those scenarios.

function Get-O365groupListforUser
{    
     param (    
           $Ownername 
           )    
    process{ 
    $groups = Get-UnifiedGroup -ResultSize Unlimited |select displayname,ManagedByDetails
    $i=0
    $groupname = ''

    Foreach($group in $groups)
    {
        $Gname= $group |Where-Object {$group.ManagedByDetails -eq "$Ownername"} |select displayname
        If($Gname -ne $null)
        {
            $j =1
            $i = $j +$i
            If($groupname)
            {
              $groupname= $groupname+","+$Gname.displayname.ToString()
            }
            else
            {
              $groupname= $Gname.displayname.ToString()
            }
        }
    }

    Write-host
    Write-host
    Write-host "---------Result-----------"
    Write-host "$($Ownername) is owner of $($i) Group(s)"
    Write-host "$($Ownername) is owner of following Groups : $($groupname)"  
    Write-host "---------Result-----------"
 }
}

$credential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $credential -Authentication Basic -AllowRedirection 
Import-PSSession $Session

#Update this variable with required user
$Ownername = "AlexW"

Get-O365groupListforUser -Ownername $Ownername  
        
Result