Reputation: 3661
How can I export several rows to a CSV? I have no input-file, I get an Array of info from Microsoft Identity Manager 2016. My code is below:
$output = @()
Foreach (//...
{
$row = New-Object PSObject -Propert @{DisplayName = $ex1; PhoneNbr = $ex2;}
$output += $row
}
Export-Csv -InputObject $output -Path $filePath
This code only writes the Array information. i.e Count, Length, etc.
Upvotes: 1
Views: 790
Reputation: 5252
You should use the advantages of Powershell
$Result = Foreach (//...){
New-Object PSObject -Propert @{DisplayName = $ex1; PhoneNbr = $ex2;}
}
$result | Export-Csv -InputObject $output -Path $filePath
Upvotes: 2
Reputation: 10019
Export-Csv
exports properties. The object $output
above has the properties Count, Length etc.
This will get you what you're after.
Foreach (//...
[array]$output += [pscustomobject]@{
DisplayName = $ex
PhoneNbr = $ex2
}
}
$output | Export-Csv -Path $filePath -NoTypeInformation
Upvotes: 2