Check permission of a user on all site collections in SharePoint Online
Also explained in the youtube video : https://youtu.be/ti9X3UNdoMY
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 = "[email protected]" # 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."
}
}