0
votes

I am quite new to PowerShell and on the site.
My issue is that I found a script which I have modified. The script is working, but only partial; it is not returning all the groups. Only 4 groups and after that is displaying "....." and no other info (you can see the picture).

actual output

Basically what I want to do is the following:
I have 100 users and I need to export the group membership of these 100 users.

 [$users = Get-Content "D:\users.txt"
$adjob = foreach ($user in $users) {
    Get-ADUser -server "myserver" –Identity $user –Properties MemberOf
}

$adjob | Select-Object Name,@{N='Group';E={$_.MemberOf -replace '^CN=(\[^,\]+),OU=.+$','$1'}} | Format-Table -AutoSize | out-file D:\users.csv][1]

Thise script should return:

name
user1
user2
user3

group

group1,group2,group3,rest of the groups for each User

group1,group2,group3,rest of the groups for each User

group1,group2,group3,rest of the groups for each User

Thank you for the help!

1

1 Answers

0
votes

Try this:

$users = Get-Content "D:\users.txt"
$adjob = foreach ($user in $users) {
      Get-ADUser -server "myserver" –Identity $user –Properties MemberOf
}
$adjob | foreach {"`n`n";$_.name, $((($_.MemberOf -split ",")| Select-String "CN") -replace "CN=","")}

The output should be username and group names right below. "`n`n" Will put two blank lines after every user.

For your particular case please try this: Enter this on PowerShell first $FormatEnumerationLimit=-1 and then replace Format-Table -AutoSize in your original script with Format-Table -AutoSize -Wrap or Format-List