Problem:
How do I export a list of all Active Directory to a .csv file users using PowerShell?
The script below will export all users:
Get-ADUser -Filter * -Properties Surname,GivenName,mail | Select-Object Name,Surname,GivenName,mail | Export-Csv c:\temp\users.csv -NoTypeInformation
The below script will export all users except for disabled users and users where the password is set to never expire (which are system accounts for most admins):
Get-ADUser -Filter {Enabled -eq $True -and PasswordNeverExpires -eq $False} -Properties Surname,GivenName,mail | Select-Object Name,Surname,GivenName,mail | Export-Csv c:\temp\users.csv -NoTypeInformation