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

    Question

  • 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.
    Thursday, March 16, 2017 4:03 PM

Answers

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

    Get-SPOSiteGroup -Site $site 

    or

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


    Then you can retrieve the users by:

    $site="https://MyCompany.bulpros.sharepoint.com/sites/site1"
    
    Get-SPOUser -Site $site -Group "SiteTitle Owners"


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

    $site="https://MyCompany.bulpros.sharepoint.com/sites/site1"
    
    $users=Get-SPOUser -Site $site -Group "SiteTitle Owners"


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

    http://stackoverflow.com/questions/6368386/comparing-two-arrays-get-the-values-which-are-not-common 

    Thursday, March 16, 2017 4:42 PM