This script aims to identify SharePoint sites where specific users hold membership, enabling efficient access management and site administration. The script utilizes PowerShell to connect to the SharePoint Online environment and iterates through all site collections, retrieving the site URLs and associated user memberships.

Script Functionality

Benefits

Target Audience

This script is primarily intended for SharePoint administrators and IT professionals responsible for managing user access and permissions within SharePoint Online environments.

Additional Notes

  1. The script requires the SharePoint Online Management Shell to be installed on the user's machine.
  2. The script utilizes the Write-Host cmdlet to display the results. For more comprehensive reporting, consider exporting the results to a CSV file.
  3. The script can be modified to search for specific groups or roles instead of individual users.
Connect-SPOService
https://test-admin.sharepoint.com
$AllSites = Get-SPOSite -Limit ALL |select URL
foreach( $user in Get-Content ""C:\userlist.txt""){
$UserLoginName = $user
foreach ($site in $AllSites){
echo "##################################################"
Write-Host " Working On:" $user "|" $site -ForegroundColor green
$UserCheck = Get-SPOUser $site.Url -Limit ALL | where-object {$_.LoginName -eq $UserLoginName}
echo "##################################################"
if ($UserCheck.LoginName -eq $user){
echo "=================================================="
Write-Host "User Have Acceess to the :" $site -ForegroundColor red
echo "=================================================="
                  $UsersiteDetails = [ordered]@{
                    UserID = $UserCheck.LoginName
                    Site = $site.Url
                   }
[PSCustomObject]$UsersiteDetails | Export-Csv .\$(get-date -f yyyy-MM-dd)_User_Site.csv -NoTypeInformation -Append
$UsersiteDetails = @()
}
}
}

foreach( $user in Get-Content ""C:\userlist.txt""){ - UPN list that you want to seach across sharepoint sites (this should be txt file)

The CSV file records the location from which the script is being executed.

I hope you find this useful :)