Articles

How to export every Conditional Access policy to a readable document

The Conditional Access page in the Microsoft Entra admin center lists your policies by name and shows them one at a time. To review the whole set, hand it to someone else or show an auditor what was in force on a given day, you need every policy in one file, with names where Microsoft Graph stores IDs. This guide exports them with Microsoft Graph PowerShell, first as raw JSON and then as a readable table per policy.

Why export Conditional Access policies at all?

Four moments need the full set in front of you:

  • Change review. Before you change one policy, you need to see the others it overlaps with. A user excluded from one policy is often covered by no other.
  • Handover. A new administrator or service provider inherits policies with names like "CA007 test" and has to know what each one does before touching it.
  • Audit evidence. The question is which policies require multifactor authentication and who is excluded, and the answer has to carry a date.
  • Incident reconstruction. After a compromise you need to know whether a policy was switched off or an exclusion added. The Entra audit log keeps those changes for 30 days unless you send it elsewhere, so an export from before the incident is often the only record of what normal looked like.

Under Entra ID > Conditional Access > Policies, the admin center shows each policy's name and state in a list. The users, target resources, conditions and controls sit in separate panes inside each policy, so comparing twenty policies means opening twenty policies.

What do you need?

  • PowerShell 7 or Windows PowerShell 5.1 and the Microsoft Graph PowerShell SDK v2. The scripts below use four of its modules:
Install-Module Microsoft.Graph.Identity.SignIns, Microsoft.Graph.Identity.DirectoryManagement, Microsoft.Graph.DirectoryObjects, Microsoft.Graph.Applications -Scope CurrentUser
  • Two delegated scopes. Policy.Read.All reads the policies and the named locations. Directory.Read.All reads the names of the users, groups, roles and applications the policies point at; it is the only scope Microsoft lists for Get-MgDirectoryObjectById. If your organization will not grant Directory.Read.All, look the objects up one type at a time instead (Get-MgUser, Get-MgGroup, Get-MgServicePrincipal, Get-MgDirectoryRoleTemplate) with User.Read.All, GroupMember.Read.All, Application.Read.All and RoleManagement.Read.Directory.
  • A role that can read Conditional Access. Global Reader or Security Reader is enough. Microsoft also lists Security Administrator and Conditional Access Administrator, which can read but can also change policies.
  • Admin consent, once. Both scopes need an administrator's consent for the Microsoft Graph Command Line Tools app. A Global Administrator or Privileged Role Administrator can grant it the first time you run Connect-MgGraph.

Everything here is read-only. No cmdlet in this guide changes a policy.

How do you export the raw policies?

This writes one JSON file per policy, named after the policy and its ID, because two policies can share a name:

# Written for the Microsoft Graph PowerShell SDK v2 (Microsoft.Graph.Identity.SignIns). It only reads.
Connect-MgGraph -Scopes "Policy.Read.All" -NoWelcome
$folder = ".\conditional-access-json-$(Get-Date -Format 'yyyy-MM-dd')"
New-Item -ItemType Directory -Path $folder -Force | Out-Null

foreach ($p in Get-MgIdentityConditionalAccessPolicy -All) {
    $file = ($p.DisplayName -replace '[\\/:*?"<>|]', '_') + " ($($p.Id)).json"
    $p | ConvertTo-Json -Depth 10 | Out-File -LiteralPath (Join-Path $folder $file) -Encoding utf8
}

The files are the faithful copy: every condition and control, including the ones a summary leaves out. Keep the folder, dated, next to whatever you write from it. Keeping JSON so you can put a deleted or broken policy back is a different job, a backup rather than a document, and How to back up Conditional Access policies covers it.

Open one file and the problem is plain. conditions.users.excludeGroups, conditions.users.includeRoles, conditions.locations.includeLocations and conditions.applications.includeApplications hold GUIDs. Nobody reviewing the policy can tell from eedad040-3722-4bcb-bde5-bc7c857f4983 that it is the break-glass group.

How do you turn the IDs into names?

Each kind of ID has its own source:

  • Users and groups in includeUsers, excludeUsers, includeGroups and excludeGroups are object IDs. Get-MgDirectoryObjectById resolves up to 1,000 of them per call. The words All, None and GuestsOrExternalUsers are not IDs.
  • Directory roles in includeRoles and excludeRoles are role template IDs, which Get-MgDirectoryRoleTemplate lists with their names.
  • Applications in includeApplications and excludeApplications are application (client) IDs, so look up the service principal by appId. The values All, Office365, MicrosoftAdminPortals and None are not IDs.
  • Named locations in includeLocations and excludeLocations come from Get-MgIdentityConditionalAccessNamedLocation; All and AllTrusted are the two built-in values.

An ID that no longer resolves usually belongs to a deleted user, group or application: the policy keeps the bare ID after the object is gone. The script prints it as NOT FOUND: <id> so it stands out.

# Written for the Microsoft Graph PowerShell SDK v2 (Microsoft.Graph.Identity.SignIns, Microsoft.Graph.Identity.DirectoryManagement,
# Microsoft.Graph.DirectoryObjects, Microsoft.Graph.Applications). It only reads. Run it first against a test tenant.
param([string] $Folder = ".\conditional-access-$(Get-Date -Format 'yyyy-MM-dd')")
Connect-MgGraph -Scopes "Policy.Read.All", "Directory.Read.All" -NoWelcome
New-Item -ItemType Directory -Path $Folder -Force | Out-Null

$policies = @(Get-MgIdentityConditionalAccessPolicy -All | Sort-Object DisplayName)
$guid     = '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$'
$states   = @{ enabled = 'On'; disabled = 'Off'; enabledForReportingButNotEnforced = 'Report-only' }

# Values that are words, not IDs.
$userWords     = @{ All = 'All users'; None = 'None'; GuestsOrExternalUsers = 'All guests and external users' }
$appWords      = @{ All = 'All resources'; None = 'None'; Office365 = 'Office 365'; MicrosoftAdminPortals = 'Microsoft Admin Portals' }
$locationWords = @{ All = 'Any location'; AllTrusted = 'All trusted locations'; '00000000-0000-0000-0000-000000000000' = 'MFA trusted IPs' }

# ID-to-name tables.
$roles = @{}
Get-MgDirectoryRoleTemplate -All | ForEach-Object { $roles[$_.Id] = $_.DisplayName }
$locations = @{}
Get-MgIdentityConditionalAccessNamedLocation -All | ForEach-Object { $locations[$_.Id] = $_.DisplayName }

$directory = @{}
$ids = @(@(foreach ($p in $policies) { $u = $p.Conditions.Users; $u.IncludeUsers; $u.ExcludeUsers; $u.IncludeGroups; $u.ExcludeGroups }) |
    Where-Object { $_ -match $guid } | Sort-Object -Unique)
for ($i = 0; $i -lt $ids.Count; $i += 1000) {
    $batch = $ids[$i..([math]::Min($i + 999, $ids.Count - 1))]
    foreach ($o in Get-MgDirectoryObjectById -Ids $batch -Types 'user', 'group') {
        $x = $o.AdditionalProperties
        $directory[$o.Id] = if ($x.userPrincipalName) { "$($x.displayName) ($($x.userPrincipalName))" } else { "$($x.displayName) (group)" }
    }
}

$apps = @{}
$appIds = @(@(foreach ($p in $policies) { $a = $p.Conditions.Applications; $a.IncludeApplications; $a.ExcludeApplications }) |
    Where-Object { $_ -match $guid } | Sort-Object -Unique)
foreach ($appId in $appIds) {
    $sp = @(Get-MgServicePrincipal -Filter "appId eq '$appId'" -Property 'displayName')
    if ($sp.Count) { $apps[$appId] = $sp[0].DisplayName }
}

function Get-Names([object[]] $Values, [hashtable] $Table, [hashtable] $Words = @{}) {
    $names = foreach ($v in $Values) {
        if (-not $v) { continue }
        if ($Words.ContainsKey($v)) { $Words[$v] } elseif ($Table.ContainsKey($v)) { $Table[$v] } else { "NOT FOUND: $v" }
    }
    @($names) -join '; '
}

$rows = foreach ($p in $policies) {
    $c = $p.Conditions; $u = $c.Users; $a = $c.Applications; $g = $p.GrantControls; $s = $p.SessionControls

    $grant = @($g.BuiltInControls | Where-Object { $_ })
    foreach ($t in @($g.TermsOfUse | Where-Object { $_ })) { $grant += "terms of use $t" }
    if ($g.AuthenticationStrength.DisplayName) { $grant += "authentication strength: $($g.AuthenticationStrength.DisplayName)" }

    $session = @()
    if ($s.SignInFrequency.IsEnabled) {
        if ("$($s.SignInFrequency.FrequencyInterval)" -eq 'everyTime') { $session += 'sign-in frequency: every time' }
        else { $session += "sign-in frequency: $($s.SignInFrequency.Value) $($s.SignInFrequency.Type)" }
    }
    if ($s.PersistentBrowser.IsEnabled) { $session += "persistent browser: $($s.PersistentBrowser.Mode)" }
    if ($s.CloudAppSecurity.IsEnabled) { $session += "app control: $($s.CloudAppSecurity.CloudAppSecurityType)" }
    if ($s.ApplicationEnforcedRestrictions.IsEnabled) { $session += 'app enforced restrictions' }
    if ($s.DisableResilienceDefaults) { $session += 'resilience defaults off' }

    $state = "$($p.State)"
    [pscustomobject]@{
        Policy            = $p.DisplayName
        State             = $(if ($states.ContainsKey($state)) { $states[$state] } else { $state })
        IncludeUsers      = Get-Names $u.IncludeUsers $directory $userWords
        IncludeGroups     = Get-Names $u.IncludeGroups $directory
        IncludeRoles      = Get-Names $u.IncludeRoles $roles
        IncludeGuests     = "$($u.IncludeGuestsOrExternalUsers.GuestOrExternalUserTypes)"
        ExcludeUsers      = Get-Names $u.ExcludeUsers $directory $userWords
        ExcludeGroups     = Get-Names $u.ExcludeGroups $directory
        ExcludeRoles      = Get-Names $u.ExcludeRoles $roles
        ExcludeGuests     = "$($u.ExcludeGuestsOrExternalUsers.GuestOrExternalUserTypes)"
        TargetApps        = Get-Names $a.IncludeApplications $apps $appWords
        ExcludedApps      = Get-Names $a.ExcludeApplications $apps $appWords
        UserActions       = @($a.IncludeUserActions) -join '; '
        AuthContexts      = @($a.IncludeAuthenticationContextClassReferences) -join '; '
        Platforms         = @($c.Platforms.IncludePlatforms) -join '; '
        ExcludedPlatforms = @($c.Platforms.ExcludePlatforms) -join '; '
        Locations         = Get-Names $c.Locations.IncludeLocations $locations $locationWords
        ExcludedLocations = Get-Names $c.Locations.ExcludeLocations $locations $locationWords
        ClientAppTypes    = @($c.ClientAppTypes) -join '; '
        SignInRisk        = @($c.SignInRiskLevels) -join '; '
        UserRisk          = @($c.UserRiskLevels) -join '; '
        DeviceFilter      = "$($c.Devices.DeviceFilter.Mode) $($c.Devices.DeviceFilter.Rule)".Trim()
        Grant             = $grant -join " $($g.Operator) "
        Session           = $session -join '; '
        Modified          = $p.ModifiedDateTime
        Id                = $p.Id
    }
}

$rows | Export-Csv -Path (Join-Path $Folder 'conditional-access.csv') -NoTypeInformation -Encoding UTF8

$body = foreach ($r in $rows) {
    $title = [System.Net.WebUtility]::HtmlEncode("$($r.Policy) ($($r.State))")
    ($r | Select-Object * -ExcludeProperty Policy, State | ConvertTo-Html -As List -Fragment -PreContent "<h2>$title</h2>") -join "`n"
}
$html = @('<!DOCTYPE html><html><head><meta charset="utf-8"><title>Conditional Access policies</title></head><body>',
          "<h1>Conditional Access policies, $(Get-Date -Format 'yyyy-MM-dd')</h1>") + $body + '</body></html>'
$html | Out-File -LiteralPath (Join-Path $Folder 'conditional-access.html') -Encoding utf8
"$($rows.Count) policies written to $Folder"

The CSV has one row per policy, for sorting and filtering in a spreadsheet. The HTML file has one two-column table per policy, headed by its name and state, which reads well printed or pasted into a document. Report-only shows as Report-only, the portal's term for enabledForReportingButNotEnforced. The grant joins its controls with the policy's operator, so mfa OR compliantDevice means either one satisfies it.

What should you check when you read the result?

Read the HTML file with these questions:

  • Report-only policies that were meant to be on. Report-only is for testing. A policy that has been in report-only for months is usually a rollout that stopped halfway.
  • Exclusions that grew. Compare the exclude columns with your last export. Every user or group there should have a reason someone can state.
  • Break-glass accounts excluded on purpose. Microsoft recommends excluding your emergency access accounts from Conditional Access policies so a misconfigured policy cannot lock everyone out. Check that they are excluded where intended, and that they are the only standing user exclusions.
  • A legacy authentication block. Look for an enabled policy with client app types exchangeActiveSync; other and the grant block. Legacy protocols cannot do multifactor authentication, so without this block a password alone still works for them.
  • All users without multifactor authentication. Find the enabled policies whose users are All users and whose target resources are All resources, and check that at least one requires mfa or an authentication strength.
  • NOT FOUND entries. Each is a deleted object still named in a policy. Remove it so the next reader is not left guessing.

Where does the script approach stop?

The script gives you a correct table, and it has limits:

  • It is a snapshot. It records the policies on the day you run it. There is no change history unless you keep every export and compare them yourself.
  • There is no diagram. Twenty policies as tables still leave the reader to work out who is covered by what. A picture of users, conditions, applications and grants answers that faster.
  • It breaks when Graph changes. Microsoft adds condition types and controls over time. The JSON already holds properties this script does not print, such as servicePrincipalRiskLevels and insiderRiskLevels, and each new one needs a new column.
  • It covers one area. Conditional Access is one part of sign-in, and sign-in is one of ten areas a tenant document needs. How to document a Microsoft 365 tenant lists the other nine and the cmdlet for each.

Where does GlacierPoint Atlas fit?

GlacierPoint Atlas writes a dated as-built document of the whole tenant from one run, as a PDF and a Word file. Its section 3, Sign-in and access, opens with a diagram of the Conditional Access policies (who, from where, to what, with what grant), then a table of every policy with its state, users, applications, conditions and grant, and a table of the named locations, along with the authentication methods and security defaults. From the second document of a tenant on, an appendix lists what was added, removed or changed since the one before, so the history the script lacks builds up as you go. The user guide shows how to connect a tenant and run it.

Checked against

  • Microsoft.Graph.Identity.SignIns 2.x (Get-MgIdentityConditionalAccessPolicy with Conditions.Users, Conditions.Applications, Conditions.Platforms, Conditions.Locations, Conditions.ClientAppTypes, Conditions.SignInRiskLevels, Conditions.UserRiskLevels, Conditions.Devices.DeviceFilter, GrantControls with Operator, BuiltInControls, TermsOfUse and AuthenticationStrength, SessionControls; Get-MgIdentityConditionalAccessNamedLocation)
  • Microsoft.Graph.Identity.DirectoryManagement 2.x (Get-MgDirectoryRoleTemplate -All), Microsoft.Graph.DirectoryObjects 2.x (Get-MgDirectoryObjectById -Ids -Types, Directory.Read.All only) and Microsoft.Graph.Applications 2.x (Get-MgServicePrincipal -Filter "appId eq '...'")
  • Permissions and roles from the Microsoft Graph v1.0 reference for listing Conditional Access policies (Policy.Read.All; Global Reader, Security Reader, Security Administrator, Conditional Access Administrator)
  • Microsoft Entra admin center path, as Microsoft Learn writes it: Entra ID > Conditional Access > Policies
  • The cmdlets and property names were checked by name against the Microsoft Graph PowerShell SDK v2 reference; the scripts were not run against a tenant by us: run them against a test tenant first