Ivan Mirchev
Ivan Mirchev

Reputation: 839

Export multiple line in CSV (Not multi-property value into CSV)

First of all I would like to clarify that my question is NOT: How to export multi-valued properties (array) into csv file.

My use case is the following: I am creating a code to audit Hyper-V infrastructure and I would like to have in one CSV cell multiple lines. For example: NIC1, NIC2 ... Disk 1, Disk 2. I do not want to use join operator and have it on a single line.

enter image description here

I am almost certain that there was an article about that and that i did managed to achieve the goal, but unfortunately I am not able to find neither the article, neither the scrip in which I have used it.

Any suggestions or ideas would be highly appreciated! :)

Upvotes: 1

Views: 756

Answers (1)

Ivan Mirchev
Ivan Mirchev

Reputation: 839

The hint was submitted by LeroyJD in the comments. @LeroyJD, Thank you very much, helped a lot! :)

To summarize for future reference: Yes, it is possible by using the new line backtick n to present in multiple lines. Sample code:

[PSCustomObject]@{
    Value1 = 'Hello'
    Value2 = "Hello `nWorld"
} | Export-Csv C:\TEMP\multiline.csv -NoTypeInformation

Invoke-Item C:\TEMP\multiline.csv

Which results into:

enter image description here

Thanks again to LeroyJD for the hint!

Upvotes: 1

Related Questions