Reputation: 31
I have a variable that will be put into powershell as a string from a different program that uses powershell. Lets say the variable is "value1, value2, value3"
in it's entirety. I want to save this as a csv file.
I've tried using export-csv
but the output I get is
#TYPE System.String
Length
34
Is there a way I can use powershell to turn the value of the string into a csv or do I have to separate each item?
Upvotes: 2
Views: 4362
Reputation: 678
$string = ("value1, value2, value3").Split(',').Replace(" ","")
[PSCustomObject]@{
'Column1'=$string[0]
'Column2'=$string[1]
'Column3'=$string[2]
} | Export-Csv .\file.csv -Append -Force -NoTypeInformation
Invoke-Item .\file.csv
You haven't said anything about what your columns are named, what type of information you're exporting and how you want it formatted. I worked with what you provided and that's it.
The answer to your question is also easily found in google.
Powershell - Output string to CSV and format
Upvotes: 3