开发者

Creating and appending CSV from powershell

开发者 https://www.devze.com 2023-03-28 19:29 出处:网络
I am trying to create a csv file from powershell with the following headers \"A,B,C,D\" Under each header, I wish to append data to the csv file after it is created.

I am trying to create a csv file from powershell with the following headers "A,B,C,D"

Under each header, I wish to append data to the csv file after it is created.

I'm currently using

$csv = "Path,Publish,Hashlist,Package`r`n"
$fso = new-object -comobject scripting.filesystemobject
$file = $fso.Cre开发者_Go百科ateTextFile($path,$true)
$file.write($csv)
$file.close()

to create the csv and trying to append it with

Add-Content browser.csv "$filepath, $publishtimestamp, $hashdestination, $packagedestination"

However, when appending the .csv file I've created here, it doesn't work correctly and looks like an encoding error. If I manually create the csv with those headers and then append, it works fine. Any ideas on the correct way to create a csv for my purposes?


If you are seeing encoding issues, use the -Encoding flag of Out-File and Add-Content to specify the encoding you want (UTF8 etc.) Why are you not using Powershell cmdlets for this? Powershell provides easier ways to write to a file, append to a file etc. Not to mention that there is the Export-Csv cmdlet for easily manipulating csv.

0

精彩评论

暂无评论...
验证码 换一张
取 消