Password Expiry

Glenn Maxwell 12,876 Reputation points
2022-03-11T06:45:28.933+00:00

Hi All

i want to pull the users list from Active Directory whose passwords expire in 10 days from powershell. Experts guide me how to pull this information.

Windows for business | Windows Client for IT Pros | Directory services | Active Directory
Windows for business | Windows Server | User experience | PowerShell
Windows for business | Windows Server | User experience | Other
0 comments No comments
{count} votes

Accepted answer
  1. Thameur-BOURBITA 36,261 Reputation points Moderator
    2022-03-11T20:39:37.66+00:00

    Try to launch the following commands, I think you will get what you want:

    $Date10 = (Get-Date).AddDays(10)
    $Date11 = (Get-Date).AddDays(11)
    Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False} -Server "DomainName" –Properties "msDS-UserPasswordExpiryTimeComputed" | Select SamaccountName,@{Name="Expiration Date";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}} | Where-Object {$_."Expiration Date" -le $Date11 -and $_."Expiration Date" -ige $Date10}
    

    Please don't forget to mark helpful reply as answer

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Thameur-BOURBITA 36,261 Reputation points Moderator
    2022-03-11T08:33:26.333+00:00

    Hi,
    This is a example of two command to select all users whose passwords expire in 10 days:

     $Date10 = (Get-Date).AddDays(10)
     Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False} -Server "DomainName" –Properties "msDS-UserPasswordExpiryTimeComputed" | Select SamaccountName,@{Name="Expiration Date";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}} | Where-Object {$_."Expiration Date" -le $Date10 }
    

    Please don't forget to mark helpful reply as answer

    1 person found this answer helpful.
    0 comments No comments

  2. Glenn Maxwell 12,876 Reputation points
    2022-03-11T13:57:00.603+00:00

    i am getting output in the below format. i only want to fetch users whose password expires in next 10 days.

    user1 1/1/1601 12:00:00 AM
    user2 1/11/2021 4:30:43 AM
    user3 1/26/2021 5:32:31 PM
    user4 1/1/1601 12:00:00 AM
    user5 10/19/2020 9:35:45 PM
    user6 1/17/2021 10:08:24 PM


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.