The New-MgIdentityConditionalAccessPolicy cmdlet allows you to create a new conditional access policy in Microsoft Entra ID (previously Azure AD). Conditional access policies help control how users access resources based on conditions such as user risk, location, device state, and required authentication methods.
Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "Policy.ReadWrite.ConditionalAccess"
Run the Graph PowerShell command below to create a new conditional access policy. Replace <name>, <conditions>, and <grant controls> with the appropriate policy details:
New-MgIdentityConditionalAccessPolicy -DisplayName <name> -State <enabled|disabled> -Conditions <object> -GrantControls <object>
This Graph PowerShell command creates a policy that requires MFA for all users:
New-MgIdentityConditionalAccessPolicy `
-DisplayName "Require MFA for All Users" `
-State "enabled" `
-Conditions @{
Users = @{
IncludeUsers = @("All")
}
} `
-GrantControls @{
Operator = "AND"
BuiltInControls = @("mfa")
}
This Graph PowerShell command restricts access to users from specific countries:
New-MgIdentityConditionalAccessPolicy `
-DisplayName "Block Access from Restricted Countries" `
-State "enabled" `
-Conditions @{
Locations = @{
IncludeLocations = @("locationID")
}
} `
-GrantControls @{
Operator = "AND"
BuiltInControls = @("block")
}
The following are some essential parameters that can be used along with the New-MgIdentityConditionalAccessPolicy command:
| Parameters | Description |
|---|---|
| -DisplayName | Specifies a display name for the conditionalAccessPolicy object |
| -State | Indicates whether the policy is enabled or disabled |
| -Conditions | Specifies the conditions (users, apps, risks) triggering the policy |
| -GrantControls | Grants controls to enforce (e.g., require MFA) |
| -SessionControls | (Optional) Controls applied to user sessions |
ADManager Plus, an identity governance and administration solution with comprehensive Microsoft Entra ID management and reporting capabilities, simplifies complex admin tasks from a single, user-friendly console: