小编Son*_*blo的帖子

如何使用变量导出-Csv?

我正在尝试使用PowerShell将8个变量写入CSV文件,但它最终只是,,,,,,,代替var1,var2,var3,var4,var5,var6,var7,var8

我的代码如下:

$newRow = "{0},{1},{2},{3},{4},{5},{6},{7}" -f $var1,$var2,$var3,$var4,$var5,$var6,$var7,$var8
$newRow = $newRow -Replace "`t|`n|`r",""
$newRow = $newRow -Replace " ;|; ",";"
$newRow += "`n"
$newRow | Export-Csv -Path $file -Append -noType -Force
Run Code Online (Sandbox Code Playgroud)

没有-Force我收到以下错误消息:

Export-Csv : Cannot append CSV content to the following file: C:\result.txt. The
appended object does not have a property that corresponds to the following column:
var1. To continue with mismatched properties, add the -Force parameter, and then
retry the command.
At C:\Test.ps1:72 char:12
+ …

csv powershell

1
推荐指数
1
解决办法
3236
查看次数

标签 统计

csv ×1

powershell ×1