What It Does
The script signs in to one client tenant as your app registration, with a certificate or a secret from the environment. It reads every application (app registration) and every service principal (enterprise app) with their secrets and certificates, and writes one row for each credential that has already expired or ends within WarnDays (default 30). It never changes anything in the tenant.
Any row ends the run in an alert, and the answer counts the expired and the expiring credentials and names the first one. With no rows it reports OK and says how many apps it checked. Enterprise apps include the signing certificates used for SAML single sign-on, so a lapsing sign-in certificate shows up here before users notice.
An expired credential that was already replaced still shows as Expired, and so does the old one next to its replacement. Add the app to ExcludeApps, or delete the old credential in Entra, to quiet it. The hidden secret text is never returned by Microsoft and is never read or printed.
It keeps no state and checks the current credentials and dates again on each run. Run it on a schedule in your RMM and alert on exit 1.
Before You Run It
- Create an app registration in the client tenant with the Graph application permission Application.Read.All and give admin consent. No license is needed.
- Put the app's certificate in the certificate store of the computer that runs the script, and use its thumbprint. A secret in the ClientSecret field is the fallback.
- Set TenantId and ClientId, and leave WarnDays at 30 unless you renew earlier.
- Expect old, replaced credentials on the first run. List those apps in ExcludeApps or delete the old credential.
- Schedule it in your RMM and alert on exit 1.
Type and Risk
- Type: Monitor. It checks one condition. It exits 1 when it finds the problem, so your RMM can alert on it, 0 when all is well, and 2 when it could not run.
- Risk: Low. It reads and changes nothing.
- Restart: It never restarts the machine.
- Typical run: Under 1 minute.
- Example answer: "App credentials: 1 expired, 2 expiring within 30 days; first: Contoso API secret 2026-12-01"
- Tested before listing with Windows PowerShell 5.1, run as SYSTEM, against its own test cases and a Microsoft 365 Business Premium test tenant.
Inputs
Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.
- TenantId: The client tenant: its ID (a GUID) or a domain such as contoso.onmicrosoft.com. Required.
- ClientId: The app registration's Application (client) ID, a GUID. Required.
- CertificateThumbprint: Thumbprint (40 hex characters) of the app's certificate with its private key in LocalMachine\My or CurrentUser\My on this computer. Preferred. When empty, the secret is read from the environment variable ClientSecret (a secure RMM field).
- WarnDays: Alert when a credential expires within this many days. Whole number, 1 to 3650. Default 30.
- ExcludeApps: Applications or service principals to skip, separated by comma, semicolon or new line: display name, app ID or object ID. Default empty.
Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.
License
Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.