Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I need assistance on getting a powershell script that would enable me pull data of all AD users and their various group they belong to .csv file.

share|improve this question

1 Answer 1

First of all, get the Quest ActiveRoles Server Commandlets here.

Then the following script should give you a start. I am using Excel to store the info, which you can save as a .csv file. Makes it a little easier with the looping and saving of values.

$a = New-Object -comobject Excel.Application
$a.visible = $True 

$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)

$c.Cells.Item(1,1)  = "Users and Groups Report"
$c.Cells.Item(1,2)  = Get-Date
$c.Cells.Item(2,1) = "User"
$c.Cells.Item(2,2) = "Groups"

$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True
$d.Font.Size = 14

$introw = 3

$users = Get-QADUser -SizeLimit $howmanyusersdoIwanttoget

foreach ($user in $users)
{
    $c.Cells.Item($introw,1) = $user.DisplayName
    $introw +=1

    $groups = Get-QADGroup -ContainsMember $user
    foreach ($group in $groups)
    {
    $c.Cells.Item($introw,2) = $group.CanonicalName
    $introw +=1
    }
}

You should be able to tune this up to meet your exact needs hopefully.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.