Categories

If you are looking for a way to obtain a list of Owners for a given M365 Group / Teams Group based on the group guid/ Identity attribute. For use with a Dynamic mapping which can then supply owners of a Target Team to an email field for a Teams archive approval request.


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 Coreview:


{

   "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"

}