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?
$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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.