Connect to SharePoint Online
Connect-SPOService -Url “https://yourtenant-admin.sharepoint.com” -Credential (Get-Credential)
Get all site collections
$allSiteCollections = Get-SPOSite
Loop through each site collection
foreach ($site in $allSiteCollections) {
$siteUrl = $site.Url
Write-Host “Site Collection: $siteUrl”
# Validate user permissions
$userEmail = "user@example.com" # Replace with the user's email address
$userPermissions = Get-SPOUser -Site $siteUrl | Where-Object { $_.LoginName -eq $userEmail }
if ($userPermissions.Count -gt 0) {
Write-Host "User has permissions on this site collection."
} else {
Write-Host "User does not have permissions on this site collection."
}
}