Skip to main content

entra-stale-accounts

Tests PyPI Python License: MIT

A read-only CLI that flags inactive Microsoft Entra ID (Azure AD) accounts past a configurable threshold. Point it at your own tenant, get a table or CSV of accounts that haven't signed in for N days — including accounts that have never signed in.

It never modifies anything: its only Microsoft Graph calls are a read of the user list and, with --licenses, a read of the tenant's subscribed SKUs. When Graph throttles (429), it waits out the Retry-After interval and retries instead of failing.

Install

pip install entra-stale-accounts

On macOS (or any system where Python blocks global pip installs), use pipx instead — it installs the CLI in its own isolated environment and puts the command on your PATH:

brew install pipx
pipx ensurepath
pipx install entra-stale-accounts

Usage

# Every enabled account with no sign-in in 90+ days
entra-stale-accounts check --days 90

# Same, as CSV — redirect to a file to hand to a manager or import elsewhere
entra-stale-accounts check --days 90 --output csv > stale.csv

# Also include already-disabled accounts, for a fuller audit
entra-stale-accounts check --days 90 --include-disabled

# Add a column of each account's license SKUs — which stale accounts
# are still holding paid licenses you could reclaim?
entra-stale-accounts check --days 90 --licenses

# CSV with the license column — a reclaim list you can sort in Excel
entra-stale-accounts check --days 90 --licenses --output csv > stale-licenses.csv

# Only the stale accounts that hold a license — skip the unlicensed ones
entra-stale-accounts check --days 90 --licensed-only
$ entra-stale-accounts check --help
Usage: entra-stale-accounts check [OPTIONS]

  List enabled Entra ID accounts with no sign-in activity in the last N days.

Options:
  --days INTEGER          Inactivity threshold in days  [default: 90]
  --output [table|csv]    Output format  [default: table]
  --include-disabled      Also show already-disabled accounts
  --licenses              Add a column of assigned license SKUs (readable
                          names need Organization.Read.All)
  --licensed-only         Only show accounts holding at least one license
                          (implies --licenses)
  --env-file TEXT         Path to a .env file with tenant credentials
  --help                  Show this message and exit.

--licenses adds a LICENSES column to the table and a trailing licenses column to the CSV. An account with several SKUs lists them in one cell, separated by ; . The report still lists every stale account, and unlicensed ones have an empty cell — add --licensed-only to drop them.

Accounts that have never signed in are always flagged — no activity at all is at least as noteworthy as an old sign-in — and sort to the top of the results.

Setup

The tool authenticates with your own Entra ID app registration via client credentials. Nothing is hardcoded — any tenant works.

1. Create an app registration

In Entra admin center → App registrations → New registration. No redirect URI needed.

Grant these application permissions under Microsoft Graph, then click Grant admin consent:

Permission Why
User.Read.All Read the user list
AuditLog.Read.All Read the signInActivity field
Organization.Read.All Optional — lets --licenses show your tenant's own SKU names

Without Organization.Read.All, --licenses still works: common SKUs resolve through a built-in table and anything unknown shows as its raw GUID.

Create a client secret under Certificates & secrets.

2. Configure credentials

Copy .env.example to .env and fill in your values:

ENTRA_TENANT_ID=your-tenant-id
ENTRA_CLIENT_ID=your-app-client-id
ENTRA_CLIENT_SECRET=your-client-secret

Plain environment variables work too, and take precedence over the .env file.

3. The licensing requirement (read this)

The Graph field this tool depends on — signInActivity — requires a Microsoft Entra ID P1 or P2 license on the tenant, not just API permissions. Without it, the field comes back empty or the request is denied — that's a licensing wall, not a bug. P1 is included in Microsoft 365 Business Premium (not Basic) and is also available standalone.

Accounts whose signInActivity is missing are reported as never signed in — if every account shows never, suspect the license, not your users.

Example output

USER PRINCIPAL NAME            DISPLAY NAME  ENABLED  LAST SIGN-IN  DAYS
-----------------------------  ------------  -------  ------------  -----
nina@contoso.onmicrosoft.com   Never Nina    true     never         never
sam@contoso.onmicrosoft.com    Stale Sam     true     2026-01-01    229

2 stale account(s) past a 90-day threshold.

Troubleshooting

"blocked by your organization's Device Guard policy" on Windows. Smart App Control (and enterprise App Control/WDAC policies) block the unsigned entra-stale-accounts.exe launcher that pip generates. The tool itself still runs fine through the signed Python interpreter — substitute the command name and keep every flag the same:

python -m entra_stale_accounts.cli check --days 90

CSV opens in Excel as one mangled column. In Windows PowerShell, > writes UTF-16, which Excel mis-detects. Redirect through Out-File instead:

entra-stale-accounts check --days 90 --output csv | Out-File stale.csv -Encoding utf8

A .env in the current directory is ignored. Fixed in 0.1.4 — upgrade with pip install --upgrade entra-stale-accounts, or pass --env-file .env explicitly on older versions.

Every account shows never. Almost always the licensing wall described in Setup, not a bug.

Development

git clone https://github.com/pobrienDev/entra-stale-accounts
cd entra-stale-accounts
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest

The test suite mocks every Graph call, it runs in milliseconds and never needs real credentials or a live tenant.

Origin

Generalized from account-lifecycle automation built for a production Microsoft 365 environment: while automating provisioning, I kept needing to check for stale accounts, so the pattern became a standalone, general-purpose tool any admin can install.

License

MIT

Metadata

Release files for entra-stale-accounts 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for entra-stale-accounts 0.3.0
File Size Uploaded Provenance Actions
entra_stale_accounts-0.3.0.tar.gz 22.1 kB With provenance Details for entra_stale_accounts-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for entra-stale-accounts 0.3.0
File Interpreter ABI Platform Actions
entra_stale_accounts-0.3.0-py3-none-any.whl Python 3 none any Details for entra_stale_accounts-0.3.0-py3-none-any.whl

Total release size: 37.7 kB

Release files / entra_stale_accounts-0.3.0.tar.gz

Download URL entra_stale_accounts-0.3.0.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
251db05eaba9f5970070496e89e9e51b635dbdb7ceeedc3ca65ec796196d6f5a
BLAKE2b-256 checksum
How to use checksums
04730bb7b29f3a3133f33816224fc1a1c486bff82253d1895c2c708d6cf760bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / entra_stale_accounts-0.3.0-py3-none-any.whl

Download URL entra_stale_accounts-0.3.0-py3-none-any.whl
Size 15.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16e584aff71cb8b9e3ba5ff53986b59dc7e035aae13886c306b7674ab7e4ed8e
BLAKE2b-256 checksum
How to use checksums
587dab66acdab02efdcfd92df9323dbd7d9362c6456c00d70c8b5254d197737d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Security for entra-stale-accounts 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for entra_stale_accounts-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page