简体   繁体   English

将字符串转换为csv Powershell

[英]Turn a string into a csv Powershell

I have a variable that will be put into powershell as a string from a different program that uses powershell. 我有一个变量,它将作为使用powershell的另一个程序中的字符串放入powershell中。 Lets say the variable is "value1, value2, value3" in it's entirety. 可以说整个变量是“ value1,value2,value3”。 I want to save this as a csv file. 我想将其另存为csv文件。

I've tried using export-csv but the output I get is 我已经尝试使用export-csv,但是得到的输出是

#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? 有没有一种方法可以使用powershell将字符串的值转换为csv,还是必须将每个项目分开?

$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. 您的问题的答案也很容易在google中找到。

Powershell - Output string to CSV and format Powershell-将字符串输出为CSV和格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM