How to Create a Conditional Access Policy for Windows 365 using the Microsoft Graph API - The Legend of Hanuman

How to Create a Conditional Access Policy for Windows 365 using the Microsoft Graph API


Today I have decided to share the script related to creating conditional access policy. You can download the same from my github link following this article. 
Prerequisites

  1. Register an EntraID App and assign the Policy.ReadWrite.ConditionalAccess permission.
  2. Install dependencies:
  3. pip install msal requests
  4. Replace placeholder values (TENANT_ID, CLIENT_ID, CLIENT_SECRET) with your Azure AD credentials.

word image 4675 1


You can download the script from my github repo here.
Explanation of this above script:

  1. Authenticates with Microsoft Graph API using the MSAL library.
  2. Defines a Conditional Access Policy that:
    • Applies to Windows 365 and related services.
    • Requires Multi-Factor Authentication (MFA).
    • Targets all users on Windows devices.
    • Applies only from trusted locations.
  3. Sends the policy to Microsoft Graph API.

How to Run

Pull or download the script from my github repo and Save the script as create_conditional_access.py or can give any name of your choice, then execute:

python create_conditional_access.py

If everything is set up correctly, you should see:

✅Conditional Access Policy created successfully!


Post Views: 194


0.00 avg. rating (0% score) – 0 votes


Share this content:

I am a passionate blogger with extensive experience in web design. As a seasoned YouTube SEO expert, I have helped numerous creators optimize their content for maximum visibility.

Leave a Comment