PowerShell for Windows Admins

Oct 28 2013   2:00PM GMT

Outputting collections from AD

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Have you ever tried anything like this:

Get-ADUser -Filter * -Properties * |
Select Name, LastLogondate, PasswordNeverExpires, Enabled,
@{N=’OU’; E={($($_.distinguishedName) -split “,”,2)[1] }},
Memberof |
Export-csv -Path users.csv -NoTypeInformation

You want some basic information about the users plus their group membership

What you get is this

Name : Fred Friday
LastLogondate :
PasswordNeverExpires : False
Enabled : True
OU : OU=Mailboxes,DC=Manticore,DC=org
Memberof : Microsoft.ActiveDirectory.Management.ADPropertyValueCollection

The data is OK apart from the group membership where you get the name of the object.

All you need is a little trick with sub expressions

Get-ADUser -Filter * -Properties * |
Select Name, LastLogondate, PasswordNeverExpires, Enabled,
@{N=’OU’; E={($($_.distinguishedName) -split “,”,2)[1] }},
@{N=’Groups’; E={$($_.Memberof)}} |
Export-csv -Path users.csv –NoTypeInformation

and then the data comes through

Name : Fred Friday
LastLogondate :
PasswordNeverExpires : False
Enabled : True
OU : OU=Mailboxes,DC=Manticore,DC=org
Groups : CN=Wednesdaylist,OU=DistributionGroups,DC=Manticore,DC=org

Enjoy

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: