Monitoring self-service password changes helps IT admins validate user-initiated password updates and ensure users are actively managing their account security. Microsoft Graph PowerShell makes it easy to retrieve these events for auditing and compliance.
This article provides a step-by-step guide and script to generate a report for “Change password (self-service)” events using the Graph PowerShell SDK v1.0.
# Connect to Microsoft Graph with required permission
Connect-MgGraph -Scopes "AuditLog.Read.All"
# Query Directory Audit Logs for "Change password (self-service)" events
$ChangePwdLogs = Get-MgAuditLogDirectoryAudit -Filter "category eq 'UserManagement' and activityDisplayName eq 'Change password (self-service)'" -All
# Display relevant fields in PowerShell console
$ChangePwdLogs | Select-Object `
@{Name = "Password Changed Time"; Expression = { $_.ActivityDateTime }},
@{Name = "User ID"; Expression = { $_.TargetResources[0].UserPrincipalName }},
@{Name = "Result Status"; Expression = {
if ($_.Result -eq "success") { "Success" }
else { "Failure" }
}} |
Format-Table -AutoSize
Here are several improvements and extensions you can add to make the script more robust:
$$Since = (Get-Date).AddDays(-30)
$RecentPwdChanges = $ChangePwdLogs | Where-Object { $_.ActivityDateTime -ge $Since }
$ChangePwdLogs | Select-Object ... | Export-Csv -Path ".\SelfServicePwdChangeReport.csv" -NoTypeInformation
To analyze success rates:
$ChangePwdLogs | Group-Object Result | Select Name, Count
Error Message | Cause | Solution |
Connect-MgGraph is not recognized | Microsoft Graph SDK is not installed | Run Install-Module Microsoft.Graph -Scope CurrentUser |
Insufficient privileges to call this API | Missing permission | Ensure the AuditLog.Read.All permission is granted and admin consent is provided |
TargetResources[0] is null | Data inconsistency | Add null checks or skip incomplete records using Where-Object { $_.TargetResources } |
This PowerShell script using Microsoft Graph offers an efficient way to monitor and audit self-service password change events. Whether you're improving security posture, preparing for compliance audits, or analyzing user behavior, this report offers valuable insights with just a few lines of code.
© m365corner.com. All Rights Reserved. Design by HTML Codex