Getting the owner of a Group in Entra ID (FKA Azure AD or AAD) involves three steps:
Get-AADGroupGet-AADGroupOwnerDefine an initial variable; the string within the name of one or more groups. Do not use asterisks here.
$SearchString = "AAD_APP_TEST_"
Leverage Get-AzureADGroup and search for the respective $SearchString variable and assign the output to a new variable, in this case $Groups.
$Groups = Get-AzureADGroup -SearchString $SearchString
Start building your ForEach loop which cycles through every group just collected. The Get-AzureADGroupOwner cmdlet can be leveraged by providing the ObjectId object belonging to the $Group variable (output of Get-AzureADGroup).
Assign the output of Get-AzureADGroupOwner to a new variable, such as $Owners.
ForEach ($Group in $Groups){
$Owners = Get-AzureADGroupOwner -ObjectId $Group.ObjectId
}
Note that each group may have more than one owner. Therefore, within this initial ForEach loop, you will need to build a nested ForEach loop to identify each owner for said group.
ForEach ($Group in $Groups){
$Owners = Get-AzureADGroupOwner -ObjectId $Group.ObjectId
ForEach ($Owner in $Owners){
...
}
}
}
Within the nested ForEach loop, you now need to build a PSCustomObject. This PSCustomObject is very similar to a Hash Table (in PowerShell) or Dictionary (in Python) but distinctly different.