Data Networking Blog
Blog for Admins

Find password expiry date for Office 365 Users

Standard

First, connect to your office 365 environment

Connect-MsolService -Credential (Get-Credential)

Every Office365 environment has a password policy which contains the notification period and validity period for passwords. Since we want to check when a users password will expire, we will first get this validity period and save it in a variable. In the same Powershell window type following command:

$valid = Get-MsolPasswordPolicy -Domain yourdomain.com | Select ValidityPeriod -ExpandProperty ValidityPeriod

Now we have our validity period saved. Let’s search the user’s in our Office365 environment. We are interested in two fields from this search, one is the UserPrincipalName, so we know which user we are talking about and second is the LastPasswordChangeTimeStamp which tells us when was the last time our user changed his/her password. If we add the validity period to this timestamp we will get the date when this user’s password will actually expire. So let’s get to work.

Get-MsolUser -All | Select UserPrincipalName, LastPasswordChangeTimeStamp | foreach{
$user = $_.UserPrincipalName
$exp = ($_.LastPasswordChangeTimeStamp).addDays($valid)
Write-Output "$user's password expires on $exp"
}

That’s it. You can now notify these users if their passwords are about to expire.

August 3, 2016 PowerShell, Script, Windows Jd
Font Size
Decrease Size Default Size Increase Size
Select Skin
Select Underlay Background
Select Overlay Background
Scheme Switcher Toggle