What It Does
This script is a High-risk Action. It creates up to three Conditional Access policies, each named with the prefix MSP Outpost baseline: MFA for all users, block legacy authentication (Exchange ActiveSync and other legacy clients), and MFA for administrators on 15 directory admin roles. The admin policy repeats the first on purpose, so admins stay covered if someone narrows policy one. New policies exclude the break-glass accounts you name, and each account must exist. On existing policies the script warns about missing exclusions without fixing them, even when Enforce=true.
Policies are created in report-only state by default. Read the Conditional Access insights and the sign-in logs for a week or two, then run it again with Enforce=true to switch them to enabled. Enforce=true on a first run creates them enabled at once: users without MFA must register at their next sign-in and legacy mail clients stop working.
It is a dry run until DryRun=false and Approve=set-conditional-access-baseline are both set. The dry run lists what it would create or enable and changes nothing. It saves the current baseline policy IDs, names and states and the Security Defaults state as JSON under the MSP Outpost backups folder before the first change, and reads the policies back afterwards.
Security Defaults and Conditional Access cannot both be on. If Security Defaults is on, the script stops before any change unless DisableSecurityDefaults=true, which turns it off first. It never edits or deletes an existing policy except to switch a report-only baseline policy to enabled, never touches a policy without the prefix, never switches a baseline policy back to report-only and never enables one an admin switched off. It does not create risk-based, location or device policies. A second run finds all three and reports Already deployed.
Before You Run It
- Have two break-glass accounts that exist. Check and fix exclusions on any existing baseline policy before enforcement, then run test-break-glass-accounts.
- Create an app registration with Policy.ReadWrite.ConditionalAccess, Policy.Read.All and User.Read.All, with admin consent. The tenant needs Entra ID P1.
- Run the dry run first and read the three policies it would create.
- Decide about Security Defaults. It keeps protecting the tenant until you enforce the new policies, so leave DisableSecurityDefaults off until you are ready.
- Run it for real in report-only, review sign-ins for a week or two, then run again with Enforce=true.
Type and Risk
- Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
- Risk: High. It is a dry run unless you set both DryRun=false and Approve=set-conditional-access-baseline, and it stops before making more than 25 changes in one run unless you raise MaxChanges. Run it once as a dry run and read the list first.
- What it changes: Creates three Conditional Access policies (report-only by default); with Enforce switches them to enabled; optionally turns Security Defaults off.
- Restart: It never restarts the machine.
- Typical run: Under 1 minute.
- Example answer: "Created 3 baseline Conditional Access policy(ies) in report-only; review sign-ins, then run again with Enforce=true"
- 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).
- BreakGlassAccounts: Sign-in names of your emergency-access (break-glass) accounts, separated by comma, semicolon or new line. Every policy excludes them. Required.
- Enforce: true to switch the baseline policies to enabled (new ones are created enabled, report-only ones are switched). Default false: report-only.
- DisableSecurityDefaults: true to turn Security Defaults off when it is on (it must be off before Conditional Access policies can be enabled). Default false: the script refuses.
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.