What is the best way of executing a function and exporting the results to csv (file needs to be timestamped)?
I am currently producing a CSV which does not contain the correct details in the correct format.
function Print-Output() {
$outputString = "hostname,os,lob"
$Applications.Keys | ForEach-Object {
$outputString+=",$_"
}
$outputString
$ComputerObjects | ForEach-Object {
$outputString="$($_.hostname),$($_.os),$($_.lob)"
$currComputerObject = $_
$currComputerObject.apps.Keys | ForEach-Object {
$outputString+=",$($currComputerObject.apps[$_])".ToLower()
}
$outputString
}
$outputString
}
Print-Output | export-csv "results.csv"
Export-CSVwhich will basically double-CSV your data. Export-CSV takes a collection of collections and outputs that to a CSV format - your data shouldn't be in a CSV format before calling the cmdlet.