Table of Contents
Prerequisite
Before you begin, make sure you’ve:
Method 1: Using Microsoft Graph API PowerShell
Connect to Microsoft Graph using the required scopes:
Connect-MgGraph -Scopes 'User.Read.All'
Check the last time password changed for a single user
$userId = '[email protected]'
$props = @('DisplayName','UserPrincipalName','LastPasswordChangeDateTime','AccountEnabled')
Get-MgUser -UserId $userId -Property $props | Select-Object $props
DisplayName UserPrincipalName LastPasswordChangeDateTime AccountEnabled
----------- ----------------- -------------------------- --------------
Chris [email protected] 12/26/2022 3:03:26 PM True
Check the last time password changed for all users
$props = @(
'DisplayName',
'UserPrincipalName',
'LastPasswordChangeDateTime',
'AccountEnabled')
Get-MgUser -All -Property $props | Select-Object $props
DisplayName UserPrincipalName LastPasswordChangeDateTime AccountEnabled
----------- ----------------- -------------------------- --------------
Bon Ben [email protected] 1/1/2023 10:40:04 AM True
Ben [email protected] 2/1/2023 8:05:26 AM True
Chris [email protected] 12/26/2022 3:03:26 PM True
Info [email protected] 1/8/2023 2:50:51 AM True
Marketing [email protected] 1/11/2023 6:16:00 AM True
Max [email protected] 1/7/2023 3:46:55 PM True
Noreply [email protected] 1/2/2023 8:56:19 AM True
Tonny [email protected] 2/2/2023 8:47:31 PM True
VIP01 [email protected] 12/27/2022 2:06:11 AM True
Export the result to a csv file:
Get-MgUser -All -Property $props | Select-Object $props | Export-Csv C:\Report.csv -Nti
Method 2: Using Azure Active Directory MSOnline PowerShell
Note
Note: Microsoft plans to retire the cmdlets in the Azure AD and Microsoft Online Services (MSOL) PowerShell modules. So the below command may not working after June 30, 2023.
You can get the last time an user changes his account password using Get-MsolUser cmdlet.
Get-MsolUser -UserPrincipalName '[email protected]' | Select DisplayName,LastPasswordChangeTimeStamp
DisplayName LastPasswordChangeTimestamp
----------- ---------------------------
Chris 12/26/2022 3:03:26 PM
Or you can run below command to get the report about the last time password changed for all account in your Microsoft 365 tenant.
Get-MsolUser -All | Select DisplayName,UserPrincipalName,LastPasswordChangeTimeStamp
DisplayName UserPrincipalName LastPasswordChangeTimestamp
----------- ----------------- ---------------------------
Marketing [email protected] 1/11/2023 6:16:00 AM
Ben [email protected] 2/1/2023 8:05:26 AM
Bon Ben [email protected] 1/1/2023 10:40:04 AM
Chris [email protected] 12/26/2022 3:03:26 PM
Noreply [email protected] 1/2/2023 8:56:19 AM
Tonny [email protected] 2/2/2023 8:47:31 PM
VIP01 [email protected] 12/27/2022 2:06:11 AM
Info [email protected] 1/8/2023 2:50:51 AM
Max [email protected] 1/7/2023 3:46:55 PM
5/5 - (2 votes)