How to filter like the O365 portal: Guest Users

This post is a part in a series of blog post which explains how to reproduce the filters which are provided by the O365 admin portal. With PowerShell scripting! This time let me show how to find B2B guest users in your tenant.

Getting a list of guest users with PowerShell

This is the filter we want to reproduce:

Screenshot of the O365 Admin portal: Filter for guest users

To get a list of all guest user accounts in your O365 / Azure AD tenant by script, use this PowerShell command. We are lucky: There is a server-side filter usable for this…

Get-AzureADUSer -All $true -Filter "UserType eq 'Guest'"

You could also use the old MSOL module:

Get-MSOLUser -All | Where {$_.UserType -eq "Guest"}

Please not that this MSOL-style filter is nowhere near as effective as the first filter command with the AzureAD module. MSOL has no server-side filtering for this property, so we have to load the full list of users first from the Azure AD backend and then filter it locally – that may take a LOT longer.

Leave a Reply

Your email address will not be published. Required fields are marked *