Get Teams/Microsoft 365 group owners

  • Last update on September 26th, 2024

Custom actions are not available in the Essentials solution.

 

If you need to obtain a list of owners for a given Microsoft 365 group or Teams group based on the group guide/identity attribute, you can use the following script:

In PowerShell:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Install-Module -Name ExchangeOnlineManagement -Verbose -Force
Update-Module -Name ExchangeOnlineManagement -Verbose -Force
Connect-ExchangeOnline -UserPrincipalName <your.name@domain.com>
$GroupData = @()
$Groups = Get-UnifiedGroup -ResultSize Unlimited -SortBy Name
$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 "; "
}
}
$GroupData
$GroupData | Export-Csv "C:\Temp\GroupOwners.csv" -NoTypeInformation
Disconnect-ExchangeOnline -Confirm:$false

OR:

$Cred = Get-Credential
Install-Module -Name AzureAD -AllowClobber -Force -Verbose
Import-Module AzureAD
Connect-AzureAD -Credential $Cred | Out-Null
$GroupData = @()
Get-AzureADMSGroup -Filter "groupTypes/any(c:c eq 'Unified')" -All:$true | ForEach-object {
$GroupName = $_.DisplayName
$GroupOwners = Get-AzureADGroupOwner -ObjectId $_.ID | Select UserPrincipalName, DisplayName
$GroupData += New-Object PSObject -Property ([Ordered]@{
GroupName = $GroupName
OwnerID = $GroupOwners.UserPrincipalName -join "; "
OwnerName = $GroupOwners.DisplayName -join "; "
})
}
$GroupData
$GroupData | Export-Csv "C:\Temp\GroupOwners.csv" -NoTypeInformation
Disconnect-AzureAD

In a CoreView custom action:

{
 "id": "9824084b-7738-4e28-bebf-a1f9aeb38822",
 "title": "Teams - Get Group Owners - V5",
 "description": "Lists the owners of a given M365 Group / Teams Group based on the Group guid / Identity attribute",
 "lastModified": "2022-02-04T20:36:22.1940000Z",
 "target": "O365Group",
 "tags": [],
 "vars": [
 {
 "name": "GroupGUID",
 "type": "string",
 "isRequired": true
 }
 ],
 "params": [
 {
 "name": "Name",
 "type": "string",
 "isDefault": true
 }
 ],
 "columns": {
 "Name": ""
 },
 "version": 5,
 "statement": "param ([string]$Name, [string]$GroupGUID)\r\n\r\n$Group = Get-UnifiedGroup -Identity $GroupGuid | Get-UnifiedGroupLinks -LinkType Owner | Select PrimarySmtpAddress\n\n$GroupOwners = $Group.PrimarySmtpAddress -join ', ' \n\n$json= @\"\n{\n\"GroupOwners\": \"$GroupOwners\"\n}\n\"@\n\nreturn $json"
}