An Azure service that is used to automate, configure, and install updates across hybrid environments.
Hello Lewis Venables
Thank you for posting your query on Microsoft Q&A platform.
You are trying to automate enabling or disabling a Conditional Access Policy in Azure using a PowerShell runbook and Microsoft Graph SDK, but you are facing two common issues that is
- Invalid JWT Access Token might be due to using managed identity without assigning the correct Microsoft Graph API application permissions.
The Graph SDK version you are using expects delegated permissions, which are not supported in Azure Automation with managed identity.
- Cmdlet Not Recognized (Update-MgIdentityConditionalAccessPolicy): This happens when the required module (Microsoft.Graph.Identity.SignIns) is either not installed properly or missing dependencies. You manually uploaded a ZIP file that did not include all required submodules.
- To avoid these, Instead of uploading ZIP modules manually try to use PowerShell to install modules directly from the PowerShell Gallery so that all dependencies are handled in a proper way. Reference: Install Microsoft Graph Module for Azure Automation using PowerShell
- Assign Graph API Permissions to Managed Identity: You must assign application level permissions (not delegated) to your Automation Account’s managed identity
Reference: https://thesysadminchannel.com/graph-api-using-a-managed-identity-in-an-automation-runbook/ - Once you have installed the Microsoft Graph modules correctly and assigned the necessary permissions to your Azure Automation account's Managed Identity, you can use the Update-MgIdentityConditionalAccessPolicy cmdlet in your runbook script. 1.Imports the required modules. 2.Authenticates using the managed identity. 3.Calls the correct Microsoft Graph cmdlet to update the Conditional Access Policy. Reference: https://learn.microsoft.com/en-us/powershell/microsoftgraph/authentication-commands?view=graph-powershell-1.0 Hope it helps.
Thanks,
Suchitra.