Link to home
Start Free TrialLog in
Avatar of Graham Moore
Graham Moore

asked on

Export all AD users and memberof name (not CN)

I have a PowerShell script which grabs all users from AD and throws out the SamAccountName & their Memberof into two separate columns. I am trying to figure out how I can amend this script so that the Memeberof column only outputs the group name and not the full CN. Can anyone offer some help please? Script:

Get-ADUser -Filter * -Properties memberof| Select samaccountname, @{n='memberOf';e={$_.memberOf -join '; '}} | Export-Csv D:\Reports\groupstest.csv -NTI

Just for some further information, I did have a script that accomplished what I wanted, but for some reason it wasn't exporting all AD users (unlike the above script), there was about 1200 or so records that were missing from the export - the script used for that was this:

Import-Module ActiveDirectory
Get-ADUser -Filter * -Properties SamAccountName,memberof | % {
  New-Object PSObject -Property @{
      UserName = $_.SamAccountName
      Groups = ($_.memberof | Get-ADGroup | Select -ExpandProperty Name) -join ";"
      }
} | Select UserName,Groups | Export-Csv D:\Reports\GroupMemberships.csv -NTI


Any help would be appreciated.

Thanks,
Graham
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Graham Moore
Graham Moore

ASKER

Thanks for your help, that seems to have done the trick!