What It Does
The script signs in as your app registration and reads every Conditional Access policy. It is read-only toward the tenant. The only thing it writes is the baseline file, and only on this computer.
Without BaselinePath it saves the current policies as a baseline file in the Baselines folder of the MSP Outpost data folder, names the file in the output and lists every policy as Exported. With BaselinePath, a JSON file this script wrote or one you edited, it compares policy by policy and writes one row per difference: Missing (in the baseline, not in the tenant), Extra (in the tenant, not in the baseline), StateChanged (enabled, disabled or report-only differs) and one Changed row per differing section: conditions, grant controls or session controls.
The comparison ignores policy IDs, the created and modified dates, empty values and the order of list values. Policy names are matched without regard to case. IDs of users, groups, roles and named locations are specific to one tenant, so a baseline from another tenant reports every policy that names one as Changed. Keep one baseline per tenant, taken when the tenant was in the state you want.
It is a Report, so it never alerts. A second run with the same baseline gives the same rows until the tenant or the file changes. Conditional Access needs Entra ID P1.
Before You Run It
- Create an app registration with the Graph application permission Policy.Read.All and give admin consent. The tenant needs Entra ID P1.
- Put the app's certificate on the computer that runs the script and use its thumbprint.
- Run it once with no BaselinePath, when the policies are the way you want them, to save the baseline.
- Keep one baseline file for each tenant and give its path in BaselinePath on later runs.
- Do not compare one tenant with another tenant's baseline.
Type and Risk
- Type: Report. It collects facts into a table and never alerts. It exits 0, or 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: "Conditional Access: 14 policies; 3 differ from the baseline (1 missing, 1 extra, 1 changed)"
- 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).
- BaselinePath: Path of the baseline JSON file to compare with. Empty (default) means: export the current policies as a baseline.
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.