One of the reports that a lot of Office 365 admins use, is to see what external users have access to the tenant in SharePoint Online. Luckily, Microsoft offers a PowerShell cmdlet in the SharePoint Online module named Get-SPOExternalUser.

While that cmdlet might seem easy and straightforward to use, there is a small catch; it can only return 50 External Users at a time due to a limit on the PageSize Parameter.

A lot of scripts that you find on the Internet will give you a command like Get-SPOExternalUser -Position 0 -PageSize 50 … and that will work great , if you have less than 50 users in your tenant! However, if you have more than 50, you will need to do something just a little bit more advanced in order to be able to see all of them. What we will do, is that we will use a For Loop wrapped in a try/catch and try to get 50 users at a time, playing with the -Position parameter until the cmdlet stops returning information. You can view the script below:
try
{
for ($i=0;;$i+=50)
{
$ExternalUsers += Get-SPOExternalUser -PageSize 50 -Position $i -ea Stop
}
}
catch
{
}
$ExternalUsers.Count
And here a screenshot example where I am checking the number of users returned, and as you can see it’s over 50, so the script worked!

[xyz-ihs snippet=”Signature-PSO365″]
Follow me on Social Media and Share this article with your friends!
|