Powershell Script to pull all groups and their members from AD - using Quest software cmdlets

GBTIS
GBTIS used Ask the Experts™
on
I have figured out how to pull the Group and the group membership for a single group and export it into an xls. I have done the following using Quest software:
get-QADGroupMember 'Domain\Administrators'-SerializeValues | export-csv C:\Install\user.csv
Fairly easy but I want to run one script to retrieve all groups and their repective members.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
PowerShell Developer
Top Expert 2010
Commented:

Get-QADGroup will give you the groups, you can pipe that into Get-QADGroupMember. e.g.:

Get-QADGroup | Get-QADGroupMember -SerializeValues | Export-CSV C:\Install\user.csv

The trouble with that is it doesn't tell you the group name, so where did you want that to appear in the scheme of things?

Chris

Author

Commented:
Above each set of user names if possible
Chris DentPowerShell Developer
Top Expert 2010

Commented:

It isn't with Export-CSV, it's rather limited in that respect (no append option).

The file format would need to be written by code. Perhaps something like this... not so simple any more and we lose the header line.

Chris
$File = "C:\Install\user.csv"
[Void](New-Item $File -Type File -Force)
 
Get-QADGroup | %{
  $_.Name >> $File
  Get-QADGroupMember $_.DN -SerializeValues | %{
    $Temp = ""
    ForEach ($Property in ($_ | Get-Member -Type NoteProperty)) {
      $Temp = "$Temp,`"$($_.$($Property.Name))`""
    }
    $Temp.SubString(1, $Temp.Length - 1) >> $File
  }
}

Open in new window

Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Thanks for trying - Let me see how this works and looks.

Author

Commented:
Still working on trying above code.

Author

Commented:
.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial