Tuesday 9 June 2020

How to export last password reset date of Azure AD/office 365 users through powershell

To get the Azure AD or office 365 etc. last password reset date i use the following steps in windows powershell.
1)
login to Azure AD
$credential = Get-Credential

(once prompt for credentials, use your username/password i.e nawaz@mycompany.com/password)

Then you may use one of the following command to connect Azure AD.

2)
Connect-AzureAD -Credential $credential
OR
Connect-MsolService -Credential $credential

Now you should be connected with Azure AD, to confirm you may use type the first few characters of any Azure AD command and press Tab key, if the command showing any suggested command then it means you are connect.

3)
Get the required detail of one user and then get/use the same command for all users.
so lets use

PS C:\Windows\system32> Get-MsolUser -UserPrincipalName nawaz@mycommany.com | select displayname, lastpasswordchangetimestamp                                                                                                               
DisplayName                                                        LastPasswordChangeTimestamp
-----------                                                        ---------------------------
Nawaz Khan System engineer           2/26/2020 7:59:58 AM

Now that we got the desired details for a single user, so we can use the same command, just replacing the -UserPrincipalName with -all switch and exporting the output to a CSV.

Get-MsolUser -All | select DisplayName,LastPasswordChangeTimeStamp >c:\path\LastPasswordChangeDate.csv

Now you may have to wait for the command to complete, it may get time to complete, as per your number of users in Azure.

No comments:

Post a Comment