PowerShell Genie

Inventory Entra users

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Get-MgUser with -All pages through the whole directory instead of stopping at the first page, and -Property maps to the underlying $select so only the four requested properties come back.

The script

1PS> Get-MgUser -All -Property DisplayName,UserPrincipalName,AccountEnabled,CreatedDateTime | Select-Object DisplayName,UserPrincipalName,AccountEnabled,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 AccountEnabled CreatedDateTime
    2 ----------- ----------------- -------------- ---------------
    3 Sample object user@example.test True 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 -Property DisplayName,UserPrincipalName,AccountEnabled,CreatedDateTime | Select-Object DisplayName,UserPrincipalName,AccountEnabled,CreatedDateTime
    1. Stage 1Get-MgUser-All -Property
    2. Stage 2Select-ObjectPositional values or no named parameters

      How it works

      Get-MgUser with -All pages through the whole directory instead of stopping at the first page, and -Property maps to the underlying $select so only the four requested properties come back. Select-Object projects the same set for display, including CreatedDateTime, which is what makes recently provisioned accounts visible.

      Adapting it

      Add -Filter to narrow the query server-side before paging begins, since retrieving a hundred thousand users and filtering locally is the slowest available way to answer a narrow question.

      Requirements

      Microsoft.Graph module with a Connect-MgGraph session holding User.Read.All.

      If the result is unexpected

      The Entra user inventory stops early or is missing expected properties.

      Graph pagination, selected properties, permissions or tenant context can limit the results.

      1. Confirm the Graph context and request the required properties with the appropriate paging behavior.

      Validate the result

      A known user and the requested fields appear, and the result count is checked against the query scope.

      Keep the check reliable

      Record tenant and selected properties; distinguish unavailable fields from empty values.

      Primary documentation

      PowerShell objects and pipelines documentation

      Practise the script’s building blocks

      Connect and read tenant users

      Connect to the fictional tenant first. Connect with User.Read.All and return fictional tenant users.

      Review the lesson

      Continue
      Genie guideInventory Entra users

      Get-MgUser with -All pages through the whole directory instead of stopping at the first page, and -Property maps to the underlying $select so only the four requested properties come back.