Monitoring when new applications are added to your Microsoft 365 environment is crucial for maintaining security and compliance. Using Microsoft Graph PowerShell, you can easily query the audit logs for "Add application" events under the "ApplicationManagement" category. In this article, we will provide you with a ready-to-use script, explain how it works, suggest further enhancements, list common use cases, cover possible errors & solutions, and wrap up with a conclusion.
# Connect to Microsoft Graph
Connect-MgGraph -Scopes AuditLog.Read.All
# Define the filter
$filter = "activityDisplayName eq 'Add 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]@{
"Added Time" = $_.activityDateTime
"Added Application" = ($_.targetResources | Where-Object {$_.Type -eq 'Application'}).displayName
"Added By (Initiator UPN)" = $_.initiatedBy.user.userPrincipalName
"Result Status" = $_.result
}
} | Format-Table -AutoSize
You can enhance this script by:
Error | Cause | Solution |
Insufficient privileges to complete the operation. | Missing permissions. | Ensure you connect with an account that has AuditLog.Read.All permission. |
No audit records found. | No "Add application" events in the queried timeframe or filter mismatch. | Remove or adjust date filters if applied, and double-check the event activity name. |
Connect-MgGraph : Access token validation failure. | Session expired or wrong tenant context. | Reconnect using Connect-MgGraph and ensure correct tenant selection. |
Target resources array is empty. | No valid target resource captured. | Add a check to handle empty target resources gracefully in the script. |
Keeping track of new applications added to your Microsoft 365 tenant is an essential part of proactive security management. This Microsoft Graph PowerShell script offers a simple yet effective way to query and display "Add application" events, making it easy to monitor and investigate new additions. With minor enhancements like CSV export and scheduling, this solution can be transformed into a robust part of your organization's auditing framework.
By regularly reviewing application additions, you can stay ahead of potential threats and maintain greater control over your cloud environment.
© m365corner.com. All Rights Reserved. Design by HTML Codex