dsquery | dsget but a means to include groupname in output

Soldato
Joined
8 Mar 2005
Posts
3,674
Location
London, UK
I am trying to return a result of unique users/groups from a AD, which may or may not include nested groups. The following command-line provides unique rows;
Code:
dsquery group domainroot -name "GROUPNAME" | dsget group -members -expand
However I want to also include the GROUPNAME in the output E.G.
"GROUPNAME,CN=foo,CN=foo,DC=foo,DC=foo,DC=foo"

Currently I pipe this out to a csv file which will then be folded into a consildated csv file, for other groups, and then cleaned up.

Happy to explore other mechanisms..

Any pointers much appreciated.
Thanks, Paul.

EDIT-
Ended up going about this is in a very backside about face way due to the return limitation.

Code:
Import-Module ActiveDirectory

$Groups = (Get-AdGroup -filter * | Where {$_.name -like "THISGROUPNAME" -or $_.name -like "THISOTHERGROUPNAME" -or $_.name -like "ORANOTHERGROUPNAME"} | select name -expandproperty name)
Foreach ($Group in $Groups) {
    <Make the dsquery | dsget call and output to an individual csv file> $Group
    }

$csvfiles = Get-ChildItem . *.csv 
Foreach ($files in $csvfiles) {
    (gc $files.PSPath) |
    % {$_ -replace '"', ""} |
    Out-File $files.PSPath -Fo -En ascii
    }
Followed by Logparser to consolidate all CSVs into a single file with an additional column which contained the groupname pulled from the csv filename generated by the dsquery| dsget call.

Phew.
 
Last edited:
Back
Top Bottom