1

Is there a way to generate a list of all External Users for the Entire SharePoint Online Tenant?

3 Answers 3

1

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.

5
  • HI Tejas, did you tried above solution Apr 27, 2021 at 4:57
  • 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 i have all the required permissions! Apr 30, 2021 at 15:30
  • try this Connect-PnPOnline -Url "tenant-admin.sharepoint.com" -Interactive May 1, 2021 at 7:16
0

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:

enter image description here

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.

5
  • 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
  • Sample script 2: - I Tried this script Apr 26, 2021 at 8:06
  • So, is it not returning all external users as expected? Apr 26, 2021 at 8:14
  • It's returning the results, but only with the Root site, and not the sub sites! Apr 26, 2021 at 10:22
0

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.

Reference:https://docs.microsoft.com/en-us/powershell/module/sharepoint-online/get-spoexternaluser?view=sharepoint-ps

And you can directly goes to the Azure AD and filter users based on user type. All the guests will be displayed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.