Purview ‐ Audit Entra Group Membership Changes that Impact Purview Policies - mattnovitsch/M365 GitHub Wiki
Customer wants a report for when group membership changes would impact their Purview policies.
Output:

- Defender for Cloud Apps
- Entra Groups
- Purview
- Entra Application
- Defender XDR - Advanced Hunting
- Navigate to Defender XDR > System > Settings > Cloud Apps > Connected Apps > App Connectors
- Check Microsoft 365 then click Edit Settings
- Check off all the boxes to get the data from Entra.
- Navigate to Entra > App registrations > All Applications > New registration
Note: You want to use a pre-existing registered application, you will need to add/check the API permissions, Client Secret, Certificates
- Copy Client ID and Tenant ID
- Navigate to Cerificates & secrets > New Client Secret
- Enter a description that is applicable to your organization and expiration per your customer requirements.
- Copy Value
- Navigate to Certificates > upload certificate
Note: I am using a certificate I generated off my laptop previously
- Copy the Thumbprint
- Navigate to API Permissions > Add a permission
- Here are the permissions needed
Note: all permissions are application based not delegated
- Graph > Directory.Read.All
- Graph > ThreatHunting.Read.All
- Office 365 Exchange Online > Exchange.ManageAsAppV2
- Grant Admin consent for your environment
- Run the following command:
Connect-ExchangeOnline
- Run the following command:
Get-MgServicePrincipal -Filter "appId eq '<APP_ID>'"
Replace APP_ID with Client ID from step 2 of Entra Application Requirements
- Copy ID value
- Run the following command: `New-ServicePrincipal -AppId "<APP_ID>" -ObjectId "<OBJECT_ID>" -DisplayName "Purview Automation App"'
Replace APP_ID with Client ID from step 2 of Entra Application Requirements and OBJECT_ID from step 3(ID Value).
- Run the following command:
Add-RoleGroupMember -Identity "Compliance Administrator" -Member "Purview Automation App"
- Download PurviewPolicyImpactedbyGroupChanges
- Open PurviewPolicyImpactedbyGroupChanges with your favorite script editor.
Note: I just use Notepad
- At the top of the script you will see the Config section, change the values accordingly:
- $TenantId = Step 2 of Entra Application Requirements
- $ClientId = Step 2 of Entra Application Requirements
- $ClientSecret = Step 5 of Entra Application Requirements
- $Thumbprint = Step 7 of Entra Application Requirements
- $Organization = Navigate to Entra > Domain Names > Custom domain names > Find the domain name that looks like .onmicrosoft.com
- Save script
You probably want to delete the word Template from the script.
- Open a PowerShell window.
- Run the script and your output should look like this:
You CSV should look like this:

Final note: since we are using certificate-based authentication, please remember to have the private key on the machine you are running this from.