In a previous article we looked at group membership for accounts in Active Directory that you can pull using PowerShell. In this short article we will look at extracting certain information for a user account or for all users in Active Directory.
For all users, you can use the following script:
Get-ADUser -filter * -Properties * | Select-Object GiveName, Surname, SamAccountName, EmailAddress, LastLogonDate, PasswordLastSet, Enabled, PasswordExpired, LockedOut > C:\Users.csv
Here is what it looks like in PowerShell:
If you want to do this for a specific user, you can use the following script:
Get-ADUser UserA -Properties * | Select-Object GiveName, Surname, SamAccountName, EmailAddress, LastLogonDate, PasswordLastSet, Enabled, PasswordExpired, LockedOut > C:\Users.csv
The above scripts will output the information to C:\users.csv.
If you want to display the information on screen for that user, you can use this script without the bracket >:
Get-ADUser UserA -Properties * | Select-Object GiveName, Surname, SamAccountName, EmailAddress, LastLogonDate, PasswordLastSet, Enabled, PasswordExpired, LockedOut
This is what the output in PowerShell will look like:
Hope it helps