Showing posts with label CSV. Show all posts
Showing posts with label CSV. Show all posts

2016-03-01

PowerShell: How to get users list with password related information from AD

The following example demonstrates how get user list from Active Directory(AD) and export to excel friendly format with non ASCII characters for later filtering:

$maxPasswordAge = (get-addefaultdomainpasswordpolicy).MaxPasswordAge.Days

Get-ADUser -Filter * -Properties CannotChangePassword,PasswordNeverExpires,LastLogonDate,Passwordexpired,passwordlastset | Select Name, SamAccountName ,CannotChangePassword, PasswordNeverExpires, Enabled, LastLogonDate, Passwordexpired, Passwordlastset,@{l="ExpiryDate";e={$_.PasswordLastSet.AddDays($maxPasswordAge)}} | sort -property name | export-csv users_export.csv -Encoding UTF8


/Geecoholic