Two ways you can use PowerShell to find Microsoft 365 group owners!

MVP

 

Hi Microsoft 365/ Azure AD friends,

 

I used the PowerShell ISE for this configuration. But you are also very welcome to use Visual Studio Code, just as you wish. Please start with the following steps to begin the deployment (the Hashtags are comments):

 

#The first two lines have nothing to do with the configuration, but make some space below in the blue part of the ISE.

Set-Location C:\
Clear-Host

 

#To be able to install the exchange online module
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

 

#Install the exchange online management module
Install-Module -Name ExchangeOnlineManagement -Verbose -Force

 

#Update the module (if necessary)
Update-Module -Name ExchangeOnlineManagement -Verbose -Force

 

#Connect to exchange online
Connect-ExchangeOnline -UserPrincipalName <your.name@domain.com>

#Get All Microsoft 365 Groups
$GroupData = @()
$Groups = Get-UnifiedGroup -ResultSize Unlimited -SortBy Name

#Loop through each Group
$Groups | Foreach-Object {

#Get Group Owners
$GroupOwners = Get-UnifiedGroupLinks -LinkType Owners -Identity $_.Id | Select DisplayName,      PrimarySmtpAddress
$GroupData += New-Object -TypeName PSObject -Property @{
GroupName = $_.Alias
GroupEmail = $_.PrimarySmtpAddress
OwnerName = $GroupOwners.DisplayName -join "; "
OwnerIDs = $GroupOwners.PrimarySmtpAddress -join "; "
}
}

 

#Get Groups Data
$GroupData
$GroupData | Export-Csv "C:\Temp\GroupOwners.csv" -NoTypeInformation

#Remove the session
Disconnect-ExchangeOnline -Confirm:$false

 

##The second way##

 

#Get Credentials to connect
$Cred = Get-Credential

 

#We need the cmdlets
Install-Module -Name AzureAD -AllowClobber -Force -Verbose

 

#Sometimes the module must be imported
Import-Module AzureAD

#Connect to AzureAD
Connect-AzureAD -Credential $Cred | Out-Null
$GroupData = @()

#Get all Microsoft 365 Groups
Get-AzureADMSGroup -Filter "groupTypes/any(c:c eq 'Unified')" -All:$true | ForEach-object {
$GroupName = $_.DisplayName

#Get Owners
$GroupOwners = Get-AzureADGroupOwner -ObjectId $_.ID | Select UserPrincipalName, DisplayName

$GroupData += New-Object PSObject -Property ([Ordered]@{
GroupName = $GroupName
OwnerID = $GroupOwners.UserPrincipalName -join "; "
OwnerName = $GroupOwners.DisplayName -join "; "
})
}

#Export Group Owners data to CSV
$GroupData
$GroupData | Export-Csv "C:\Temp\GroupOwners.csv" -NoTypeInformation

 

#Remove the session
Disconnect-AzureAD

 

Now you know two ways how to identify Microsoft 365 groups owners. I am absolutely aware that this is nothing spectacular. However, I wanted to share some experience with you.

 

I hope this article was useful. Best regards, Tom Wechsler

 

P.S. All scripts (#PowerShell, Azure CLI, #Terraform, #ARM, etc.) that I use can be found on github! https://github.com/tomwechsler

 

0 Replies