This code works when ran on its own, I'm trying to combine both commands output to a single csv, formatted with the correct headers.
$objectIDs = Get-AzureADGroupMember -ObjectId x | select objectid,displayname,mail
$groups = foreach ($objectID in $objectids) {
Get-AzureADUser -ObjectId $objectid.ObjectId | select mail ;
Get-AzureADUserMembership -ObjectId $objectID.ObjectId | Where-Object { $_.displayname -like '*xxxxxxxx*' } | select displayname
}
$groups | Out-File C:\temp\test.csv
Basically, I need the mail and specific group name in a csv.