PowerShell Genie

Find disabled Entra users

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

The -Filter argument hands accountEnabled eq false to Graph as an OData expression so the service performs the selection.

The script

1PS> Get-MgUser -All -Filter "accountEnabled eq false" -Property DisplayName,UserPrincipalName | Select-Object DisplayName,UserPrincipalName

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
    2 ----------- ------------------ --------------
    3 Adele Vance adelev@contoso.com True
    4 Alex Wilber alexw@contoso.com True
    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 "accountEnabled eq false" -Property DisplayName,UserPrincipalName | Select-Object DisplayName,UserPrincipalName
    1. Stage 1Get-MgUser-All -Filter -Property
    2. Stage 2Select-ObjectPositional values or no named parameters

      How it works

      The -Filter argument hands accountEnabled eq false to Graph as an OData expression so the service performs the selection. Only the display name and UPN are requested and projected, which keeps each response small.

      Adapting it

      Append a createdDateTime clause to the filter string to focus on accounts old enough that removing them is uncontroversial, rather than reviewing every disabled account in the tenant.

      Requirements

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

      If the result is unexpected

      A disabled-user report disagrees with the Entra portal.

      AccountEnabled may not have been selected, or the session may point to a different tenant.

      1. Retrieve AccountEnabled explicitly for a known account and verify the tenant before applying the filter.

      Validate the result

      The report uses actual Boolean values rather than treating an unrequested property as disabled.

      Keep the check reliable

      Select every property used by a filter and retain the tenant identifier in output.

      Primary documentation

      PowerShell objects and pipelines documentation

      Continue
      Genie guideFind disabled Entra users

      The -Filter argument hands accountEnabled eq false to Graph as an OData expression so the service performs the selection.