We help IT Professionals succeed at work.

how can i arrange the display of a powershell query against the ActiveDirectory ?

Erwin Pombett
on
Hello experts,

I need to query an OU and get all groups and all members of those groups in a display as follow :

group_name, member, objectclass.
blabla, blibli, group
bleble, bloblo, user
....

here's how i can get all the Groups :
$path_to_group = "OU=STD, OU=GROP,OU=bigOU, OU=net, OU=cl"
$groups = Get-ADGroup -SearchBase $path_to_group -filter {GroupCategory -eq "Security"}

then i loop over the groups to get the members as follow
      foreach($group in $groups)
      {
            Get-ADGroupMember -identity $group
      }


questions:
1
do i get all groups in an OU with the filter : -filter {GroupCategory -eq "Security"}
or do i need to change or add another "GroupCategory". ?

2.
how can i arrange a display as already discribed.

group_name, member, objectclass.
blabla, blibli, group
bleble, bloblo, user


thank you in advance.

toshi_
Comment
Watch Question

Top Expert 2015

Commented:
For the filter just use *, this will get ALL groups.

$groups = Get-ADGroup -SearchBase $path_to_group -filter *

Open in new window

Author

Commented:
Hello Guy,

thank you for your reply.

I already find the groups out of the OU.
Then i'm looping through the groups in order to get all childrens.

What I need is to get all Groups in the OU and recursively continue until i have the users.

thank your for further help
toshi
I created an output variable as string. then i fillded up with all the values i wanted as an output.

i returned that value. On my command line i piped that content to  

 |Out-File "C:\toMyExportedFile.csv"

toshi

Author

Commented:
i did not receive information concerning the output.....
i dit it on my own.

toshi