Monitoring updates to applications in your Microsoft 365 environment is vital for ensuring that only authorized changes are made. With Microsoft Graph PowerShell, you can effectively query audit logs to track "Update application" events under the "ApplicationManagement" category.
In this article, we will provide a ready-to-use script, explain how it works, suggest further enhancements, highlight use cases, address possible errors and their solutions, and conclude with key takeaways.
# Connect to Microsoft Graph
Connect-MgGraph -Scopes AuditLog.Read.All
# Define the filter
$filter = "activityDisplayName eq 'Update application' and category eq 'ApplicationManagement'"
# Fetch the audit logs
$logs = Get-MgAuditLogDirectoryAudit -All `
-Filter $filter `
-Property activityDateTime, activityDisplayName, initiatedBy, result, targetResources
# Parse and output the results
$logs | ForEach-Object {
[PSCustomObject]@{
"Updated Time" = $_.activityDateTime
"Updated Application" = ($_.targetResources | Where-Object {$_.Type -eq 'Application'}).displayName
"Updated By (Initiator UPN)" = $_.initiatedBy.user.userPrincipalName
"Result Status" = $_.result
}
} | Format-Table -AutoSize
| Error | Cause | Solution |
| Insufficient privileges to complete the operation. | User account lacks necessary permissions. | Ensure that AuditLog.Read.All permission is granted and consented. |
| No audit records found. | No matching events exist or timeframe too narrow. | Broaden the search period or validate if updates occurred. |
| Connect-MgGraph : Access token validation failure. | Session timeout or incorrect context. | Reconnect using Connect-MgGraph with correct parameters. |
| Target resources array is empty. | No associated application in event. | Implement a fallback in script to handle missing targetResources. |
Keeping track of application updates is crucial for safeguarding your Microsoft 365 environment. This Microsoft Graph PowerShell script provides a streamlined and efficient way to monitor "Update application" events. By integrating enhancements like automated runs, CSV exports, and alerts, organizations can ensure continuous visibility into changes affecting their applications. Regular monitoring fosters better security practices, maintains compliance, and helps respond swiftly to incidents involving application modifications.
© m365corner.com. All Rights Reserved. Design by HTML Codex