Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrik23/1bdbee1fa221dd80949ff6495bfa0142 to your computer and use it in GitHub Desktop.
Save mrik23/1bdbee1fa221dd80949ff6495bfa0142 to your computer and use it in GitHub Desktop.
PowerShell script to retrieve external users that have been added via modern sharing experience on files and folders (with verification code to email). These users are not retrieved with Get-SPOExternalUser and not present in Azure AD.
<#
Script to retrieve external users that have been added via modern sharing experience on files and folders (with verification code to email).
These users are not retrieved with Get-SPOExternalUser cmdlet and not added as guest users in Azure AD.
Requires: SharePoint Online Management Shell > https://www.microsoft.com/en-us/download/details.aspx?id=35588
#>
Connect-SPOService -Url https://<tenantName>-admin.sharepoint.com
Get-SPOSite -Limit All | ForEach-Object {
if (($_.SharingCapability -ne "Disabled") -and ($_.SharingCapability -ne "ExistingExternalUserSharingOnly")) {
$url = $_.Url
Get-SPOUser -Site $url -Limit All | Where-Object -Property LoginName -match guest | Select-Object -Property @{n="Url"; e={$url}}, DisplayName, LoginName
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment