Forum Discussion

Adaministrator's avatar
Adaministrator
Copper Contributor
Jul 03, 2023

Account Bindings/Dependencies

Hi team,

 

I've scoured various forums for an answer to this, but they seem to either address something slightly different to what I'm looking for, or, the recommended solution doesn't really work for me.

 

I'm looking to export a list of SharePoint sites that one specific account (which is currently disabled) is either a member or an admin of. Without drilling through each individual site - of which we have over 300 - and manually reviewing the membership, what's the best way to do this? 

 

I've tried audit reports, I've tried searching the contentclass:STS_Site search, and I've tried various PowerShell strings which don't quite show me what I'm looking for. 

 

Any assistance would be hugely appreciated, thank you

  • Adaministrator 

    To export a list of SharePoint sites where a specific account (whether a member or admin) is associated, you can use PowerShell and SharePoint Online Management Shell. Here's a script that can help you achieve this:

     

    # Connect to SharePoint Online
    Connect-SPOService -Url "https://yourdomain-admin.sharepoint.com"
    
    # Specify the account for which you want to find the sites
    $account = "email address removed for privacy reasons"
    
    # Create an array to store the site URLs
    $siteUrls = @()
    
    # Get all SharePoint sites
    $sites = Get-SPOSite -Limit All
    
    # Loop through each site and check membership
    foreach ($site in $sites) {
        # Check if the account is a member or admin of the site
        $users = Get-SPOUser -Site $site.Url | Where-Object { $_.LoginName -eq $account }
        if ($users.Count -gt 0) {
            # If the account is found, add the site URL to the array
            $siteUrls += $site.Url
        }
    }
    
    # Output the list of site URLs
    $siteUrls

    To run this script:

    1. Install SharePoint Online Management Shell if you have not already. You can download it from the Microsoft Download Center.
    2. Open Windows PowerShell or PowerShell ISE with administrative privileges.
    3. Copy and paste the script into the PowerShell window.
    4. Modify the $account variable to specify the account for which you want to find the sites.
    5. Run the script.

    The script will connect to your SharePoint Online environment, loop through each site, and check if the specified account is a member or admin of each site. The URLs of the sites where the account is found will be displayed as the output.

    Please note that you need to have the necessary permissions to run the script and access the SharePoint sites. Also, make sure you have the SharePoint Online Management Shell module installed and properly configured. The text/steps and Code were created with the help of AI.

    My answers are voluntary and without guarantee!

     

    I hope this helps!

  • NikolinoDE's avatar
    NikolinoDE
    Gold Contributor

    Adaministrator 

    To export a list of SharePoint sites where a specific account (whether a member or admin) is associated, you can use PowerShell and SharePoint Online Management Shell. Here's a script that can help you achieve this:

     

    # Connect to SharePoint Online
    Connect-SPOService -Url "https://yourdomain-admin.sharepoint.com"
    
    # Specify the account for which you want to find the sites
    $account = "email address removed for privacy reasons"
    
    # Create an array to store the site URLs
    $siteUrls = @()
    
    # Get all SharePoint sites
    $sites = Get-SPOSite -Limit All
    
    # Loop through each site and check membership
    foreach ($site in $sites) {
        # Check if the account is a member or admin of the site
        $users = Get-SPOUser -Site $site.Url | Where-Object { $_.LoginName -eq $account }
        if ($users.Count -gt 0) {
            # If the account is found, add the site URL to the array
            $siteUrls += $site.Url
        }
    }
    
    # Output the list of site URLs
    $siteUrls

    To run this script:

    1. Install SharePoint Online Management Shell if you have not already. You can download it from the Microsoft Download Center.
    2. Open Windows PowerShell or PowerShell ISE with administrative privileges.
    3. Copy and paste the script into the PowerShell window.
    4. Modify the $account variable to specify the account for which you want to find the sites.
    5. Run the script.

    The script will connect to your SharePoint Online environment, loop through each site, and check if the specified account is a member or admin of each site. The URLs of the sites where the account is found will be displayed as the output.

    Please note that you need to have the necessary permissions to run the script and access the SharePoint sites. Also, make sure you have the SharePoint Online Management Shell module installed and properly configured. The text/steps and Code were created with the help of AI.

    My answers are voluntary and without guarantee!

     

    I hope this helps!

Resources