In this article, we will be sharing the PowerShell command that may be required to find user accounts with “Password Never Expire” selected in user accounts in the Active Directory environment. When creating a user in Active Directory, the “Password Never Expire” option is selected as in the figure below.
With the command below, we will examine how to get the csv output of the user accounts with “Password Never Expire” selected in the user accounts in the Active Directory environment, via Powershell.
Search-ADAccount -PasswordNeverExpires -UsersOnly -ResultPageSize 99999 -ResultSetSize $null | Select-Object Name, SamAccountName, DistinguishedName | Export-CSV “C:\Reports\PasswordNeverExpiresUsersList.csv” -NoTypeInformation
After the output of the above command is completed, .csv output will be created under the “C:\Report” directory. You can see it by opening the “PasswordNeverExpiresUsersList.csv” file located here.
Note: Here we have created a “Report” file under the “c:\” directory. You can create a file with a different name or save the “csv” file in a different location.
Removing “Password Never Expire”
After finding the user accounts with “Password Never Expire“, we right-click on the user and click “Properties” to turn off/on the “Password Never Expire” option. You can remove the “Password Never Expire” option in the “Account -> Account options:” section on the “Properties” page.