Szafa
Szafa

Reputation: 23

ad goup list.txt piped to Get-ADGroupMember

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

Answers (2)

E.V.I.L.
E.V.I.L.

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

CB.
CB.

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

Related Questions