My basic need is easy to understand, but I've not spent much time in CSV manipulation and I'm completely confuddled as to the best approach to make this work lol.
My end goal is to get a CSV file from select groups in AD (name like Group*) where the final formatted CSV appears like:
"displayname","samaccountname","description","memberof"
"Mouse, Mickey","mmouse","disney movie","Group1"
"Mouse, Mickey","mmouse","disney movie","Group2"
"Mouse, Mickey","mmouse","disney movie","Group3"
"Rabbit, Roger","rrabbit","Touchstone Pictures","Group1"
"Rabbit, Roger","rrabbit","Touchstone Pictures","Group2"
So that, for each group a user is in, it will be a single CSV line for that group. I currently can get a single standard CSV of:
"Mouse, Mickey","mmouse","disney movie","Group1,Group2,Group3,etc"
Using this syntax:
$Groups = Get-ADGroup -Filter {name -like "Group*" -or name -like "Another Group*" or name -like "More Groups*" -or name -like "Yet Another Group*"}
$GroupMembers = $Groups | Get-ADGroupMember
$GroupUsers = $GroupMembers | Get-ADUser -Properties displayName,samaccountname,description,memberof
$Export = $GroupUsers | select displayName,samaccountname,description,@{name="MemberOf";expression={($_.Memberof | %{($_.substring(3) -split ",OU=")[0]}) -join ","}}
$Export | Export-Csv -path E:\Cognos\Users.csv -NoTypeInformation
But once I have the CSV file, I can't seem to figure out a ForEach loop that works, or if I need modify my original multi-value statement for memberof prior to sending it to Select.
Thank you very much in advance!!! ![]()