Close Menu
    Facebook X (Twitter) Instagram
    Sunday, October 12
    X (Twitter) LinkedIn Reddit RSS
    All about Endpoint Management
    • Home
    All about Endpoint Management
    Home»configmgr»Automation»Use PowerShell to audit the Conditional Access Policies and alert via email

    Use PowerShell to audit the Conditional Access Policies and alert via email

    Eswar KonetiBy Eswar KonetiJanuary 27, 9:39 pm2 Mins Read Automation 4,982 Views
    Share
    Facebook Twitter LinkedIn Reddit

    Conditional Access in Azure Active Directory needs no introduction. To read more information about Conditional Access, please refer to https://docs.microsoft.com/en-us/azure/active-directory/conditional-access/overview

    In my recent assignment, there was an ask to back up the conditional access policies every day and also notify through email for a list of conditional policies that are created or modified in the last 24 hours.

    I know that there are many blog posts out there to monitor the conditional access policies by enabling the diagnostic settings (export the audit logs), creating logic apps, power automate and other tools in a programmatic way and alert instantly, but that needs subscription and other extra components to achieve it. What if you don’t have any subscription or extra components in place but you like to monitor the CA policies using built-in tools such as PowerShell script?

    In this blog post, I will show you how to backup the conditional access policy and notify email with a list of policies that are changed or modified. Using this solution, won’t alert you the changes instantly but notify the changes at a scheduled interval.

    We will use the built-in Azure AD preview PowerShell cmdlet Get-AzureADMSConditionalAccessPolicy to get the Azure Active Directory conditional access policies.

    Why preview? There are some important details about the CA policy such as the creation date, modified date available only in preview at the time of writing this blog post.


    image

    To ease your BAU tasks, this script is useful. You need to edit the script with email information such as sender, receiver, SMTP, user account to connect to Azure AD (encrypted format), etc.

    Once you define all the variables, you can schedule the task to run every 24 hours for email notifications.
    You can run the script with a least-privileged account such as a global reader or any equivalent account that has read access to Conditional Access Policies.

    This script needs the Azure AD PowerShell module to be pre-installed on the device where you run the script.
    The output of the script will look like something below.

    Conditional Access policy changes file:

    Email notification incase any changes to the conditional Access policies

    and finally the script can be downloaded from GitHub here

    You can always customize the script to suite your needs.

    Hope you find this post useful!

    Alert changes AzureAD backup conditional access EMS PowerShell Script
    Share. Twitter LinkedIn Email Facebook Reddit

    Related Posts

    Export Microsoft Entra ID User Authentication Methods to CSV using PowerShell & Microsoft Graph API

    August 13, 2:08 pm

    Automating Intune Deployment Rings Using Entra ID Dynamic Groups and Regex

    July 01, 10:31 pm

    Exporting Intune Win32 Apps with All Properties Using PowerShell and Microsoft Graph

    June 30, 7:01 pm

    4 Comments

    1. Suraj Malusare on March 30, 2022 3:10 PM

      Hi Eswar,

      Will it also record the personal email ID has modified the policy ?

      Reply
      • Eswar Koneti on April 7, 2022 9:36 PM

        Hi,
        you can use audit logs to see who modified the policy.
        The script will audit the changes made to the CA policies and record it.

        Thanks,
        Eswar

        Reply
    2. Bhoopathy M on February 3, 2022 7:08 PM

      Best article as usual Eswar.

      Reply
      • Eswar Koneti on February 4, 2022 8:44 AM

        Thanks Bhoopathy.

        Regards,
        Eswar

        Reply

    Leave a ReplyCancel reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Sign Up

    Get email notifications for new posts.

    Author

    I’m Eswar Koneti ,a tech enthusiast, security advocate, and your guide to Microsoft Intune and Modern Device Management. My goal? To turn complex tech into actionable insights for a streamlined management experience. Let’s navigate this journey together!

    Support

    Awards

    Archives

    © Copyright 2009-2025 Eswar Koneti, All rights reserved.

    Type above and press Enter to search. Press Esc to cancel.

     

    Loading Comments...