Powershell – Find all users with password never expires

active-directorypowershellwindows-server-2008-r2

I am looking to query AD via Powershell in order to see all user accounts within my forest who have their password set to never expire.

I found a few scripts online using a quick google search but none of them appear to work as expected. I then found the following on technet (https://technet.microsoft.com/en-us/library/finding_users_whose_password_never_expires%28v=ws.10%29.aspx) however when I run the line:

Search-ADAccount -PasswordNeverExpires | FT Name,ObjectClass -A

I only receive a very small number of results and I know that the list returned is missing a large number of users who I know have this option set.

Please can someone tell me what is incorrect with this script or what the reason for the small result set could be?

Best Answer

I use the below to and it works.

get-aduser -filter * -properties Name, PasswordNeverExpires | where { $_.passwordNeverExpires -eq "true" } | where {$_.enabled -eq "true"} 

It searches against AD database to find user's with "PasswordNeverExpires" set to "True" then returns the results in the Powershell console.

edit for wording and wrong cmdlet and to add the below To cleanup the results add this to the end of the above powershell code

| Format-Table -Property Name, PasswordNeverExpires -AutoSize