$filesremoved | export-csv -Path E:\Code\powershell\logs\filesremoved.txt -NoTypeInformation我也试过
$filesremoved | export-csv -Path E:\Code\powershell\logs\filesremoved.txt -NoTypeInformation -NoClobber该文件似乎每次都会被覆盖。有没有办法继续向文件中添加内容?
我收到错误
Export-Csv : A parameter cannot be found that matches parameter name 'Append'.发布于 2014-01-11 00:07:15
Export-Csv的-Append参数直到PowerShell 3.0才存在。
在CSV2.0中解决这个问题的一种方法是导入现有的PowerShell,创建一些新行,追加两个集合,然后再次导出。例如,假设test.csv:
"A","B","C"
"A1","B1","C1"
"A2","B2","C2"您可以使用如下脚本将一些行附加到此CSV文件:
$rows = [Object[]] (Import-Csv "test.csv")
$addRows = 3..5 | ForEach-Object {
New-Object PSObject -Property @{
"A" = "A{0}" -f $_
"B" = "B{0}" -f $_
"C" = "C{0}" -f $_
}
}
$rows + $addRows | Export-Csv "test2.csv" -NoTypeInformation运行此脚本,test2.csv的内容将为:
"A","B","C"
"A1","B1","C1"
"A2","B2","C2"
"A3","B3","C3"
"A4","B4","C4"
"A5","B5","C5"发布于 2014-01-11 00:14:01
我不知道$filesremoved包含什么,但是要在PS2.0中添加CSV-output,您可以尝试如下所示:
$filesremoved | ConvertTo-Csv -NoTypeInformation | Select-Object -Skip 1 | Out-File -Append -FilePath "test2.csv"Select-Object -Skip 1用于移除头部。但是,您应该指定所需的列顺序、分隔符和可能的编码,如下所示:
$filesremoved | Select-Object -Property Name, Date | ConvertTo-Csv -Delimiter ";" -NoTypeInformation | Select-Object -Skip 1 | Out-File -Append -Encoding ascii -FilePath "test2.csv"发布于 2014-01-11 00:10:46
一种可能性是:
$CSVContent = $filesremoved | ConvertTo-Csv
$CSVContent[2..$CSVContent.count] | add-content E:\Code\powershell\logs\filesremoved.txthttps://stackoverflow.com/questions/21048650
复制相似问题