20 February 2012

Export-Csv -InputObject

Export-Csv does not accept an array of strings as an input object;
The array must be first coverted into objects because Export-Csv need a custom object with multiple properties, not a series of single property strings;

For Export-Csv each objects is a new row of data in the resulted csv file;
Properties of the object will become columns headers and property values - rows;

To overcome this you can use:

$string = "name","age", "location" >> exported_data.csv # this will be the header;
$string = $name + "," + "21" + "," + "Romania" >> exported_data.csv # first csv line;

No comments:

Post a Comment