I`m trying to figure out a way to retrieve a list of site collections whose owners match a list of email addresses I extract from an AD group.
The following code gives me a list of email addresses stored in a variable as an array.
$group = "CONTOSO"
$users = Get-ADGroup -Filter {Name -like $group} | Get-ADGroupMember -Recursive |
Select-Object -Unique |
Get-ADUser -Properties Mail |
Select-Object Mail |
Sort-Object Mail
I would like to get all owners of a site collection in my tenant that is on that list and output the site collection name.
However, I`ve been unable to get the owner email addresses from all site owners in our tenant let alone compare them to the extracted AD email addresses.
I tried this code to retrieve all owners of site collections in the tenant.
Get-SPOSiteGroup -Site https://contoso.sharepoint.com/ |
Where-Object {$_.Title -eq "Owners"} | Select-Object Users
Any help is much appreciated.
Thanks.