What It Does
The script signs in as your app registration and lists delegated consents whose scope contains a permission from the high-risk list, and application permissions on Microsoft Graph, Exchange Online or SharePoint Online that are on the list. It changes nothing.
The list is fixed in the script: mail read, write and send, mailbox settings, all files, all sites, directory write, role and application management, group write, user write, Exchange full access and the grant-management permissions. Microsoft publishes no high-risk list, so the choice is the script's. Read the list before you trust a quiet result. The delegated check matches scope names across resources. The application permission check is limited to the three services above. The owners of the apps are not checked.
Microsoft's own apps, the apps in AllowedApps and the app the script signs in as are skipped. Any other grant ends the run in an alert with one row per grant, and the answer names the first few apps. A client whose app record cannot be read is shown with an empty name.
It keeps no state, so a second run reports the same grants until they are removed or allowed. To remove them, run remove-risky-app-consents, which starts as a dry run.
Before You Run It
- Create an app registration with the Graph application permissions Directory.Read.All and Application.Read.All and give admin consent.
- Put the app's certificate on the computer that runs the script and use its thumbprint.
- List the apps you accept in AllowedApps, by app ID or exact display name.
- Read the high-risk list in the script header before you trust a result with no rows.
- Decide who owns the follow-up before you schedule it, then 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 2 minutes.
- Example answer: "Risky app consents: 4 grant(s) for 3 app(s): Mail Merge Pro (Mail.ReadWrite Mail.Send), Cloud Backup (Files.ReadWrite.All), +1 more"
- 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 Application (client) ID of the app registration that holds the Graph permissions. Required.
- CertificateThumbprint: Thumbprint of the app's certificate (private key in LocalMachine\My or CurrentUser\My). Preferred. When empty, the app secret is read from the environment variable ClientSecret (a secure/hidden RMM field; never an argument).
- AllowedApps: Apps you accept, by application (client) ID or exact display name, separated by comma, semicolon or new line. 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.