Skip to main content

Listing Disabled Users in Microsoft Entra ID with Read-Only Microsoft Graph PowerShell

List disabled Entra ID users with Get-MgUser and User.Read.All: filter accountEnabled, select properties, page with -All, count, export and disconnect.

KBY Technologies10 min readFoundation10 min
Listing Disabled Users in Microsoft Entra ID with Read-Only Microsoft Graph PowerShell

Advertising disclosure: this article includes partner links. KBY may earn a commission if you sign up or buy through one, at no extra cost to you. How we make money.

Before you begin

  • A non-production Microsoft Entra tenant with a few test users, at least one of them disabled.
  • An admin account in that tenant that can grant admin consent for User.Read.All.
  • PowerShell with the Microsoft Graph PowerShell SDK, including the Microsoft.Graph.Users module.

Underlined words are defined in the KBY Lexicon. Tap or click one to see what it means.

When an auditor or a manager asks which accounts in the tenant are switched off, the answer is one filtered query away. In that state is the accountEnabled property, and Microsoft Graph PowerShell can list every user where it is false without holding any permission to change anything.

The catch is that Graph returns only what you ask for, in pages, and only what your sign-in is allowed to see. A query that looks right can quietly return blank columns or stop at the first hundred users. Knowing why it does that is what turns a copied command into a list you can sign your name to.

#What you will learn

  • Explain how a delegated Microsoft Graph PowerShell session decides what you can read.
  • Connect with the read-only User.Read.All permission and confirm the session’s scopes, tenant and account.
  • List disabled users with a server-side filter, all pages and the properties you need.
  • Tell a basic filter from an advanced query, and read the error you get when you mix them up.
  • Count, export and hand over the result, then disconnect and tidy up.

#What you need

  • A non-production Microsoft Entra tenant, such as a developer or trial tenant, with a handful of test users. Clear the Account enabled box on at least one of them beforehand, so the query has something to find.
  • An admin account in that tenant that can grant admin consent. User.Read.All needs admin consent, and Microsoft’s getting-started guide notes this typically means the Privileged Role Administrator role.
  • PowerShell with the Microsoft Graph PowerShell SDK installed, including the Microsoft.Graph.Users module.

Everything in the exercise reads data. The only change it makes to the tenant is the consent you grant on first sign-in, and the last section shows where to review and revoke that.

#How a query decides who comes back

Every Get-MgUser call becomes a request to the Microsoft Graph /users endpoint. Three separate things shape the answer: what your session may read, which properties you selected, and which filter operators Graph will accept. Each one fails in its own recognisable way, so it pays to keep them apart.

#
Delegated permissions and who is really asking

Connect-MgGraph -Scopes signs you in with delegated access. Here the app acts on behalf of the signed-in user, and Microsoft is explicit that it cannot reach anything that user could not. The scope is therefore a ceiling on the app, not a grant of extra power to you.

For listing users, Microsoft ranks the delegated permissions from least to most privileged: User.ReadBasic.All, User.Read.All, User.ReadWrite.All, Directory.Read.All and Directory.ReadWrite.All. The basic scope covers only display name, first and last name, email address and photo, so it cannot show accountEnabled. User.Read.All reads the full profile and writes nothing, which makes it the right choice here.

Laptop screen displaying code and performance graphs with eyeglasses resting on the keyboard.
Photo by Daniil Komov on Pexels

#
Why most properties stay hidden until you ask

Graph returns a small default set of user properties: businessPhones, displayName, givenName, id, jobTitle, mail, mobilePhone, officeLocation, preferredLanguage, surname and userPrincipalName. Everything else, accountEnabled included, must be named with $select. In PowerShell that is the -Property parameter.

The PowerShell object still has an AccountEnabled member when you skip -Property, but the value is empty. That is why a forgotten -Property produces a tidy table with a blank column rather than an error.

#
Basic filters and advanced queries

The user resource documents accountEnabled as supporting $filter with eq, ne, not and in. Not every operator works on a plain request, though. Microsoft’s advanced query page uses this exact property as its example: accountEnabled eq false works by default, while accountEnabled ne true needs advanced query parameters.

Advanced queries are served from a separately indexed store. To use them you send the ConsistencyLevel: eventual header and, except for $search, the $count parameter. In Get-MgUser those are -ConsistencyLevel eventual and -CountVariable. Leave them off a query that needs them and Graph replies with Request_UnsupportedQuery.

The flowchart below shows how the choice of operator decides which form of the command you run, before both paths meet at the same checks.

Rendering diagram...

#
Pages, and why -All matters

Graph never sends a large directory in one response. The /users endpoint has a default page size of 100 users and a maximum of 999. Get-MgUser without -All returns the first page only, so in a tenant with more than 100 disabled accounts the list stops short with no warning. Adding -All tells the cmdlet to follow every page.

#A leavers audit in practice

Picture a quarterly access review. Internal audit asks for every disabled account, whether it is a member or a guest, and whether it comes from on-premises . The last point matters because onPremisesSyncEnabled is true for a user currently synced from Active Directory. Such a user is managed there, so any change goes through the Active Directory team, as in unlocking a locked-out Active Directory account.

The analyst connects with User.Read.All and runs one filtered query with -All. They select displayName, userPrincipalName, accountEnabled, userType, onPremisesSyncEnabled and createdDateTime. The export goes to audit with the time the query ran, because the list describes the directory at that moment and no later.

Two questions often follow. If someone asks whether a disabled account tried to sign in, the evidence is in the sign-in logs, covered in finding why a user’s sign-in failed. If an expected leaver is missing, check whether the account was deleted rather than disabled. A deleted user follows different rules, explained in restoring a deleted user within the 30-day window.

Close-up of a hand writing in a notebook with a checklist for effective task management.
Photo by Jakub Zerdzicki on Pexels

#Your turn: list the disabled accounts in a lab tenant

The outcome to aim for is a CSV of every disabled test user, with the counts from two different query forms agreeing. Each step reads data only, and each says what you should see before you move on.

  1. Connect with the one read-only permission the exercise needs, and approve the consent prompt in the lab tenant:
    1Connect-MgGraph -Scopes "User.Read.All"

    Expected evidence: a “Welcome To Microsoft Graph!” message.

  2. Confirm where you are and what the session holds:
    1Get-MgContext | Format-List Account, TenantId, AuthType
    2Get-MgContext | Select-Object -ExpandProperty Scopes

    Expected evidence: your lab admin account, the lab tenant ID, Delegated, and User.Read.All among the scopes. Stop and run Disconnect-MgGraph if the tenant is not your lab, or if write scopes such as User.ReadWrite.All appear.

  3. See the hidden-property problem for yourself:
    1Get-MgUser -Top 5 | Format-Table DisplayName, UserPrincipalName, AccountEnabled

    Expected evidence: five users with an empty AccountEnabled column, because the property was not selected.

  4. Run the real query, selecting the properties you need:
    1$disabled = Get-MgUser -Filter "accountEnabled eq false" -All -Property "id,displayName,userPrincipalName,accountEnabled,userType,onPremisesSyncEnabled,createdDateTime"
    2$disabled | Format-Table DisplayName, UserPrincipalName, AccountEnabled, UserType, OnPremisesSyncEnabled
    3$disabled.Count

    Expected evidence: every account you disabled, each showing AccountEnabled as False, and a count that matches.

  5. Try the advanced operator without advanced parameters, so you recognise the error later:
    1Get-MgUser -Filter "accountEnabled ne true"

    Expected evidence: an error with the code Request_UnsupportedQuery.

  6. Run it properly, with the count Graph calculates for you:
    1Get-MgUser -Filter "accountEnabled ne true" -CountVariable CountVar -ConsistencyLevel eventual
    2$CountVar

    Expected evidence: $CountVar equals $disabled.Count. If you disabled a user moments ago, wait a minute and run both again before treating a mismatch as a problem.

  7. Export the list for whoever asked for it:
    1$disabled | Select-Object DisplayName, UserPrincipalName, UserType, OnPremisesSyncEnabled, CreatedDateTime |
    2    Export-Csv -Path .\disabled-users.csv -NoTypeInformation

    Expected evidence: a CSV with a header row and one row per disabled user. -NoTypeInformation drops the #TYPE header line that older Windows PowerShell writes; Microsoft notes it is not required from PowerShell 6.

  8. End the session:
    1Disconnect-MgGraph

    Expected evidence: no error. The token for this window is revoked, so any further Graph cmdlet needs a fresh Connect-MgGraph.

Following along? Tap a step’s number to tick it off.

#How to check your work

A list is only useful if you can show it is complete and correct. Three checks cover that, and none of them changes anything.

  • The column is real. Every row shows AccountEnabled as False. A blank value means -Property was missing, so the filter worked but you cannot prove it from the output.
  • Two methods agree. The count from the basic filter with -All matches the $CountVar from the advanced query. They reach Graph by different routes, so agreement is good evidence that nothing was cut off.
  • The portal agrees. Spot-check two or three names in the Microsoft Entra admin center. Each should show as disabled, matching the export.

#Mistakes that give the wrong list

Most wrong answers come from the query running successfully and returning less than you think. These are the ones to watch for.

  • No -All. The result stops at the first page of 100 users. Small labs hide this, and large tenants expose it in an audit.
  • No -Property. AccountEnabled, UserType and OnPremisesSyncEnabled come back empty, because none is in the default set.
  • Filtering on the client. Piping every user into Where-Object works, but it downloads the whole directory first. The server-side -Filter sends back only the users you asked about.
  • Reaching for a write scope. Directory.ReadWrite.All or User.ReadWrite.All also lists users, but it lets the same session change them. A reporting task needs User.Read.All and nothing more.
  • Mixing up the operators. ne, not and counts need -ConsistencyLevel eventual and -CountVariable. When the error says Request_UnsupportedQuery, add both, or rewrite the filter with eq.
  • Treating it as a leavers list. A disabled account may be a service account kept switched off, or a user on long leave. The query shows the state; someone who knows the business decides what it means.

#Running the same query against production

The commands do not change for a production tenant, but the care around them does. Connect only with User.Read.All, and check Get-MgContext before every run. Admin consent applies to the whole organisation, so the scopes list can show permissions someone granted earlier. If it includes write scopes you did not ask for, raise it with whoever manages app consent.

The export holds names and sign-in identities, so store it where the request came from and delete your local copy when the request closes.

Consent is the one tenant change this work makes, and it can be reviewed afterwards. In the admin center, go to Entra ID then Enterprise apps then All applications, open the app, and select Permissions. The Admin consent tab lists organisation-wide grants, and each can be removed with Revoke permission. Microsoft documents this for the Cloud Application Administrator or Application Administrator roles.

Escalate rather than act when the list raises a question you cannot settle by reading. That includes a disabled account that still owns resources, a synced account that looks wrong in Active Directory, or an account nobody can explain. Each needs its owner, not a quick change from the same PowerShell window.

#Worth remembering

  • User.Read.All is enough to list disabled users and grants no write access.
  • Delegated access never exceeds what the signed-in account could do itself.
  • accountEnabled is not returned by default, so always select it with -Property.
  • accountEnabled eq false is a basic filter; ne, not and counts need -ConsistencyLevel eventual and -CountVariable.
  • Use -All, compare two counts, and end with Disconnect-MgGraph.

About this page

Credited to

Dates

Published

Sources

This page lists no external sources.

Corrections

No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.

Found this useful? Follow KBY for more like it.

Reader Interaction

Comments

Add a thoughtful note on Listing Disabled Users in Microsoft Entra ID with Read-Only Microsoft Graph PowerShell. Comments are checked for spam and held for moderation before appearing.

Loading comments...

More from KBY that goes with this article.

Discover more

Was this useful?

Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.

Build practical engineering skills.

Receive new lessons, learning paths, practical exercises and early-career guidance.