powershell export to csv

davidm27
davidm27 used Ask the Experts™
on
I have the following powershell code which works perfectly without the export-csv command it displays the users and the number of groups they are a member of. With the export it only shows the count not the username any help would be great
$Users = Get-QADUser -Sizelimit 0
$Users | foreach {
$Name = $_.Samaccountname
$count = ($_.memberof | Measure-Object).count
Write-Output "$Name,$Count"
} | Export-Csv c:\scripts\newgroupn05.csv

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
$Users = Get-QADUser -Sizelimit 0
$Users | foreach {
    $Name = $_.Samaccountname
    $count = ($_.memberof | Measure-Object).count
    $output += "$Name,$Count"
}

$output | Export-Csv c:\scripts\newgroupn05.csv

Open in new window

Sorry, missed a line.

$output = @()
$Users = Get-QADUser -Sizelimit 0
$Users | foreach {
    $Name = $_.Samaccountname
    $count = ($_.memberof | Measure-Object).count
    $output += "$Name,$Count"
}

$output | Export-Csv c:\scripts\newgroupn05.csv

Open in new window

Author

Commented:
cheers

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