Get site collections where owner is on list of email addresses from AD


  • 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 |
        Where-Object {$_.Title -eq "Owners"} | Select-Object Users

    Any help is much appreciated.

    Thursday, March 16, 2017 4:03 PM


  • First you can check the name of the group. It should be something like "SITETITLE Owners" or your custom name.

    Get-SPOSiteGroup -Site $site 


    Get-SPOSiteGroup -Site $site | where {$_.Title -match "Owners"}

    Then you can retrieve the users by:

    Get-SPOUser -Site $site -Group "SiteTitle Owners"

    If you want to compare them, then save your results to a variable:

    $users=Get-SPOUser -Site $site -Group "SiteTitle Owners"

    You can then compare the two arrays using Compare-Object: 

    Thursday, March 16, 2017 4:42 PM