Powershell AD query script needed

Need a powershell script to get these fields and save to csv.

Username
Group membership
Last login
Display name
OU
Enabled/disabled
cj_cbAsked:
Who is Participating?
 
QlemoConnect With a Mentor Batchelor, Developer and EE Topic AdvisorCommented:
Since a user can be member of multiple groups, how would you like to have that displayed? Just a comma-separated list?
Are the Quest AD tools an option? They simplify things with pre-W2008R2 domains.
0
 
cj_cbAuthor Commented:
yes just a comma-seperated list is good, i will look into Quest but we are 2008r2 active domain.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Then we can use the ActiveDirectory module, and the Get-AD* cmdlets ...
0
 
cj_cbAuthor Commented:
that may work, was hoping for a little more detail on how to use the cmdlet.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Sorry, I wasn't finished, but had to leave.
Something like this?
Import-Module ActiveDirectory
Get-ADUser -Filter * -Properties * |
  select Name,
        @{n='Group Membership'; e={($_.MemberOf | % {(get-adgroup $_).Name}) -join ','}},
        LastLogonDate, DisplayName, DistinguishedName, Enabled |
  Export-CSV 'C:\Results.csv'

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.