Powershell: Get AD users with Password Never Expires

We can get the list of AD users whose password never expire using Active Directory Powershell cmdlet Search-ADAccount with the parameter PasswordNeverExpires. In this article, I am going to write Powershell script to get the list of AD users whose password never expire and export AD users with password never expires to CSV file.

Run the following command to import Active Directory cmdlets.

Import-Module ActiveDirectory

Powershell command to list password never expire ad users:

Search-ADAccount –PasswordNeverExpires | Select Name, DistinguishedName

Find Password Never Expire AD Users from specific OU

We can set target OU scope by using the parameter SearchBase in Search-ADAccount cmdlet. The following command select and list all the AD users whose password never expires from the Organization Unit ‘TestOU’.

Import-Module ActiveDirectory
Search-ADAccount  -SearchBase "OU=TestOU,DC=TestDomain,DC=Com" –PasswordNeverExpires |
Select -Property Name,DistinguishedName

Export Password Never Expire AD Users to CSV using Powershell

We can export powershell output into CSV file using Export-CSV cmdlet. The following command export selected properties of all the password never expire AD users to CSV file.

Import-Module ActiveDirectory
Search-ADAccount –PasswordNeverExpires | Select -Property Name,DistinguishedName |
Export-CSV "C:\PasswordNeverExpireADUsers.csv" -NoTypeInformation -Encoding UTF8

CSV output of Password Never Expire AD users report:

Powershell script to find AD users whose password never expires
Advertisement

Leave a Comment