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