Skip to content

Get All Users With Passwords That Never Expire and Output to a File In PowerShell for Active Directory

by on August 4, 2014

image

 

Very easy solution:

Search-ADAccount –PasswordNeverExpires | FT Name,ObjectClass –A | out-file -filepath C:\ps_output\nonexpiringusers.txt –noclobber

Note: The -noclobber parameter means an existing file will not be overwritten. I usually append the date to my output file names.

You Can Also Filter by OU (AD “Folder”)

Search-ADAccount –PasswordNeverExpires –SearchBase “ou=MyCompany External Users,DC=mydomain,DC=com” | FT Name,ObjectClass –A | out-file -filepath C:\ps_output\nonexpiringusers_external.txt –noclobber

Search-ADAccount –PasswordNeverExpires –SearchBase “ou=MyCompany External Users,DC=mydomain,DC=com” | FT Name,ObjectClass –A | out-file -filepath C:\ps_output\nonexpiringusers_external.txt –noclobber

For Output to CSV Use the Select-Object command

Search-ADAccount –PasswordNeverExpires –SearchBase “ou=External Users,DC=mydomain,DC=com” | Select-Object name, Department | export-csv C:\ps_output\nonexpiringusers_external.csv –noclobber

Search-ADAccount –PasswordNeverExpires –SearchBase “ou=External Users,DC=mydomain,DC=com” | Select-Object * | export-csv C:\ps_output\nonexpiringusers_external.csv –noclobber

or dos shorthand and output to txt

Search-ADAccount –PasswordNeverExpires –SearchBase “ou=External Users,DC=mydomain,DC=com” | Select-Object name, Department > C:\ps_output\nonexpiringusers_externalDos.txt –noclobber

NOTE: change > to >> to append rather than overwrite!

Export Users with Passwords That Don’t Expire Including Last Logon Date and Operational Units

My favorite and most requested solution is the below:

Search-ADAccount –PasswordNeverExpires –SearchBase “ou=External Users,DC=mydomain,DC=com” | Select-Object name, LastLogonDate, DistinguishedName | export-csv C:\ps_output\nonexpiringusers_external_ou_date.csv –noclobber

Note: this file can now be easily opened by end users in excel!

Advertisements
Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: