PowerShell Script to Get Password Expiry Of a user or All users

As an administrator, we get query that how to find password expiry date for a single user or get details of all the users.

 You can run the below command either on a domain controller or a member server.

  • Log in to a Domain Controller.
  • Import the Active Directory PowerShell module Import-Module ActiveDirectory.
  • Run the below PowerShell command to find the user’s created in last 30 days.
  1. For A Single User
Get-ADUser "username" –Properties "DisplayName", "msDS-UserPasswordExpiryTimeComputed" |Select-Object -Property "Displayname",@{Name="ExpiryDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}

2. For All Users

Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False} –Properties “DisplayName”, “msDS-UserPasswordExpiryTimeComputed” |Select-Object -Property “Displayname”,@{Name=”ExpiryDate”;Expression={[datetime]::FromFileTime($_.”msDS-UserPasswordExpiryTimeComputed”)}}


Comments

Leave a comment