PowerShell Genie

Find guest users

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

A userType eq 'Guest' filter is evaluated by Graph, with the literal in single quotes because OData string comparisons require them.

The script

1PS> Get-MgUser -All -Filter "userType eq 'Guest'" -Property DisplayName,UserPrincipalName,CreatedDateTime | Select-Object DisplayName,UserPrincipalName,CreatedDateTime

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 DisplayName UserPrincipalName CreatedDateTime
    2 ----------- ----------------- ---------------
    3 Sample object user@example.test 2026-09-10T12:00:00Z
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    Get-MgUser -All -Filter "userType eq 'Guest'" -Property DisplayName,UserPrincipalName,CreatedDateTime | Select-Object DisplayName,UserPrincipalName,CreatedDateTime
    1. Stage 1Get-MgUser-All -Filter -Property
    2. Stage 2Select-ObjectPositional values or no named parameters

      How it works

      A userType eq 'Guest' filter is evaluated by Graph, with the literal in single quotes because OData string comparisons require them. Paging is handled by -All, and CreatedDateTime travels with the names so the age of each invitation shows in the result.

      Adapting it

      Add ExternalUserState to the requested properties to split guests who accepted their invitation from those still sitting in PendingAcceptance, and the pending ones can usually be removed without consulting anyone.

      Requirements

      Microsoft.Graph module and a Graph session with User.Read.All.

      If the result is unexpected

      Expected guests are missing or external-looking addresses are classified as members.

      An external email domain does not by itself determine the UserType property.

      1. Inspect UserType and identity data for a known account in the intended tenant.

      Validate the result

      Guest results satisfy the chosen UserType filter; exceptions are reviewed by identity rather than address alone.

      Keep the check reliable

      Keep guest classification separate from email-domain classification.

      Primary documentation

      PowerShell objects and pipelines documentation

      Continue
      Genie guideFind guest users

      A userType eq 'Guest' filter is evaluated by Graph, with the literal in single quotes because OData string comparisons require them.