Powershell AD query script needed

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

Group membership
Last login
Display name
Who is Participating?
QlemoConnect With a Mentor Batchelor and DeveloperCommented:
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.
cj_cbAuthor Commented:
yes just a comma-seperated list is good, i will look into Quest but we are 2008r2 active domain.
QlemoBatchelor and DeveloperCommented:
Then we can use the ActiveDirectory module, and the Get-AD* cmdlets ...
cj_cbAuthor Commented:
that may work, was hoping for a little more detail on how to use the cmdlet.
QlemoBatchelor and DeveloperCommented:
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

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.