Project maintained by timhaintz Hosted on GitHub Pages — Theme by mattgraham

Password Expiry Date

Introduction

Below is a one liner to advise when a user password will expire. I have used the Group Policy default setting of 42 days in the example below. The Maximum Password Age link has further information on the Group Policy setting.

Script

PowerShell Code Block

((Get-ADUser -Identity azureadmin -Properties PasswordLastSet).passwordlastset).adddays(42)

Results

((Get-ADUser -Identity azureadmin -Properties PasswordLastSet).passwordlastset).adddays(42)

Saturday, November 24, 2018 9:39:35 PM

Explanation

Cmdlets used

Get-ADUser

The Get-ADUser cmdlet gets a specified user object or performs a search to get multiple user objects.

-Identity

Specifies an Active Directory user object.

-Properties

Specifies the properties of the output object to retrieve from the server. Use this parameter to retrieve properties that are not included in the default set.

adddays() method

By using parentheses around (Get-ADUser -Identity azureadmin -Properties PasswordLastSet).passwordlastset) I can call the adddays() method. Scripting Guy has a great blog post called Adding and Subtracting Dates with PowerShell if you would like further backgound. Using adddays() allows me to take a DateTime object and add days or, using a -, subtract days.

Conclusion

The above one liner is a quick and easy way to check when a user password will expire. It also shows how PowerShell can be used to view and manipulate date time objects.

Hope you’re having a great day and this is of use.

Thanks, Tim.