VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Help creating a CSV file

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"

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Got it. Thank you LucD.

Reply
0 Kudos