Reputation: 23
Hi I'm new to powershell. I have text file with ad group list and I want list all users for each group. I tried pip line :
Get-Content '.\test list.txt' | % { Get-ADGroupMember -Recursive $_ } | select name
but in result i get single column with all users list belongs to all groups in text file.
how i can get csv table with all groups names in column heading and users list below each group name?
Thanks
Upvotes: 1
Views: 2321
Reputation: 2166
Hope this helps you. It requires PS3.0:
Get-Content .\list.txt | % {(Get-ADGroupMember -Identity $_ -Recursive).Name | Out-File -FilePath "$_.txt"}
$hash = @{}
Get-Content .\list.txt | % {$hash["$_"] = (Get-ADGroupMember -Identity $_ -Recursive).Name}
$hash
I don't use CSV very much but I bet hashes are easy to format into CSV files.
Upvotes: 0
Reputation: 60986
Try this ( not tested ):
Get-Content '.\test list.txt' |
SELECT @{N="Group Name";e={$_}},@{N="Members";`
E={ (Get-ADGroupMember -Recursive $_) -JOIN ';' }} | fl
Upvotes: 1