Hi,
I am trying to create a CSV file using below but in the the output file, the names are in the same line, but I need names in the different line.
Please help
$str_list = "MyDB1 MyApp1 MyZEO1"
$obj_list = $str_list -replace(" ",",") | Select-Object @{Name='Name';Expression={$_}}
$obj_list | export-csv -path "D:\reports\test.csv" -NoTypeInformation -UseCulture
Output
"Name"
"MyDB1 MyApp1 MyZEO1"
By replacing the blanks with a comma, the input still remains a single string.
A handier method would be to split by the blanks into an array, and then use a calculated property to give a name to the property.
Something like this for example
$str_list = "MyDB1 MyApp1 MyZEO1"
$str_list.split(' ') |
Select @{N='Name';E={$_}} |
Export-Csv -Path "D:\reports\test.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
By replacing the blanks with a comma, the input still remains a single string.
A handier method would be to split by the blanks into an array, and then use a calculated property to give a name to the property.
Something like this for example
$str_list = "MyDB1 MyApp1 MyZEO1"
$str_list.split(' ') |
Select @{N='Name';E={$_}} |
Export-Csv -Path "D:\reports\test.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Got it. Thank you LucD.