Pull the credential list for every application in your tenant and sort by expiry. Somewhere near the bottom you’ll find a client secret that doesn’t expire until a date your grandchildren will recognize. Attached to a service principal nobody has signed into since the pandemic. Holding Application.ReadWrite.All. Owned by a former employee whose account was deleted eighteen months ago.
That’s not a hygiene problem. That’s a standing credential with tenant-wide write access and no human accountable for it. If an attacker finds it before you do, they don’t need to phish anyone, they already have the keys, and the keys never expire.
App registration sprawl is the attack surface nobody put on the risk register. Every proof-of-concept, every Logic App someone wired up in 2021, every “just testing” multi-tenant app a contractor consented to on your behalf, it’s all still there, still holding whatever permissions it was granted, still a valid identity. Entra doesn’t age them out. Nobody does.
So before anyone touches delete, inventory. Enumerate every application, read its credentials, and flag the ones with long-dated or passwordless-but-privileged secrets. Read-only, paginated, with error handling, because a tenant with thousands of apps will throttle you, and a silent half-finished query is worse than no query.
That CSV is your worklist. Cross-reference it with sign-in activity so you know what’s actually dead versus what’s quietly carrying a production workload at 3am. Service principal sign-ins live in the sign-in logs, pull the last-used date per app and mark anything that hasn’t authenticated in 90 days. “Looks old” is not evidence. “Has not authenticated in six months and has no owner and holds no high-risk grant” is a candidate.
Audit the consents while you’re there. Delegated grants in oauth2PermissionGrants, application-role assignments in appRoleAssignedTo. You are looking for the fat ones: Mail.ReadWrite, Files.ReadWrite.All, anything .ReadWrite.All, directory roles handed to an app. Half of these were approved by an admin clicking through a consent prompt years ago and nobody has looked since. Those are the grants that turn one compromised secret into a full mailbox exfiltration.
Now the part the delete-happy crowd gets wrong. You do not delete. You disable, and you wait.
Set the service principal’s AccountEnabled to $false and leave it. A disabled SP can’t authenticate, so the attack surface is gone immediately, but the object still exists, so when the batch job that nobody documented fails next Tuesday, you flip one flag and it’s back. Delete the object and you’ve got no undo; you’re rebuilding app registrations from memory while a payroll run sits broken.
Run it with -WhatIf first. Read the output. Then run it for real, and start a timer. Thirty to ninety days of a disabled app with no complaints is your evidence to delete. Not before.
And the test tenant somebody spun up for a migration in 2022 and never decommissioned? That’s not an app registration problem, that’s a whole directory of them, guests, secrets, consents, the lot, sitting outside your monitoring with real credentials. Inventory it the same way, then actually tear it down. An orphaned app is a liability. An orphaned tenant is a breach waiting for a slow news week.
