Password Expiry

Glenn Maxwell 10,146 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 Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,480 questions
Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,389 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,206 questions
Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,932 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,389 questions
0 comments No comments
{count} votes

Accepted answer
  1. Thameur-BOURBITA 32,586 Reputation points
    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 32,586 Reputation points
    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 10,146 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