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={$_.membe rOf -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\GroupMembership s.csv -NTI
Any help would be appreciated.
Thanks,
Graham
Get-ADUser -Filter * -Properties memberof| Select samaccountname, @{n='memberOf';e={$_.membe
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\GroupMembership
Any help would be appreciated.
Thanks,
Graham
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER