Is there a way to generate a list of all External Users for the Entire SharePoint Online Tenant?
3 Answers
You can list all external users for the entire SharePoint Online tenant by using following option.
Method 1: Use PnP PowerShell to list all external users.
Connect-PnPOnline -Url "https://tenant-admin.sharepoint.com"
Get-PnPExternalUser
For more details use this link List external users
Method 2: Use graph api to list all external users
Use below endpoint
https://graph.microsoft.com/v1.0/users/?$filter=userType eq 'guest'
Please mark as answer if you are satisfied and upvote it.
-
-
Hi Rajat, I Tried using Connect-PnPOnline -Url "tenant-admin.sharepoint.com" Get-PnPExternalUser - But it give me 403 Forbidden error, any ideas? Apr 30, 2021 at 10:11
-
PnP-PowerShell must be approved by your admin before you used it. Apr 30, 2021 at 15:02
-
-
Yes, you can get the list of external users using SharePoint online PowerShell or PnP PowerShell.
Sample script 1:
Connect-SPOService -Url https://office365admin123-admin.sharepoint.com-credential $credentials
$i = 0
ForEach($site in Get - SPOSite)
{
$i++
Write - Host "*********"
Write - Host "Site number: "
$i
$site.Url
$site.Owner
$site.SharingCapability
Get - SPOExternalUser - SiteUrl $site.Url
}
Output:
Source: Report On External Users In SharePoint Online
Sample script 2:
#Import SharePoint Online Management Shell
Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking
#Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$ReportOutput ="C:\Temp\ExternalUsersRpt.csv"
#Get Credentials to connect
$Cred = Get-Credential
#Connect to SharePoint Online Tenant Admin
Connect-SPOService -URL $AdminSiteURL -Credential $Cred
#Get All Site Collections
$SiteCollections = Get-SPOSite -Limit All
#Iterate through each site collection and get external users
Foreach ($Site in $SiteCollections)
{
Write-host -f Yellow "Checking Site Collection:"$Site.URL
Try {
For ($x=0;;$x+=50) {
$ExternalUsers += Get-SPOExternalUser -SiteUrl $Site.Url -Position $x -PageSize 50 -ErrorAction Stop | Select DisplayName,EMail,InvitedBy,AcceptedAs,WhenCreated,@{Name = "SiteUrl" ; Expression = {$Site.url}
}
}
}
catch {}
}
#Export the Data to CSV file
$ExternalUsers | Export-Csv -Path $ReportOutput -NoTypeInformation
Source: SharePoint Online: Find All External Users using PowerShell - You can also find the other ways to fetch external users in this reference.
-
I tried this one, but i see that it's generating data for only the Root sites, Anyway to get data of the sub-sites as well? Apr 26, 2021 at 7:51
-
Did you try 2nd script? You can also try the different ways (Site Collection Wise or using PnP PowerShell) given in 2nd link in my answer. Apr 26, 2021 at 8:03
-
-
-
It's returning the results, but only with the Root site, and not the sub sites! Apr 26, 2021 at 10:22
You can use scripts mentioned above or directly use the cmdlet
$AdminSiteURL="https://<domain>-admin.sharepoint.com"
$Cred = Get-Credential
Connect-SPOService -URL $AdminSiteURL -Credential $Cred
Get-SPOExternalUser
It will directly list all the external users.
And you can directly goes to the Azure AD and filter users based on user type. All the guests will be displayed.