我正在尝试将内容添加到.txt文件中,但是当我使用Out-File
时,结果会被覆盖,而当我使用Add-Content
或Set-Content
格式时,结果会被更改。
foreach ($item in (Get-ChildItem .\Upload)) {
Write-Host -Object "Uploading $item..."
$Send = Add-FTPItem -Session $Session -Path $FTPPlace -LocalPath .\Upload\$item -Overwrite -ErrorAction SilentlyContinue #>> .\up.txt #.\Upload\test.txt
if ($Send.Name -eq $item.Name) {
$Rec = "OK"
} else {
$Rec = "!!!-FAIL-!!!"
}
$array = $line, $item, $connect, $Rec
$FailTable = New-Object -TypeName PSObject -Property ([ordered]@{
"FTP Server" = $array[0];
"File" = $array[1];
"Connected" = $array[2];
"Uploaded" = $array[3]
})
$FailTable >> .\stats.txt
#$FailTable | Set-Content .\stats.txt
#Write-Output $FailTable | Add-Content .\stats.txt
#Add-Content .\stats.txt $FailTable
$FailTable | Out-File '.\stats.txt' #-NoClobber
}
工作效果Out-File
:
FTP Server File Connected Uploaded ---------- ---- --------- -------- 10.80.59.170 test.txt OK OK
以及工作Set-Content
和Add-Content
的结果:
@{FTP Server=10.80.59.170; File=Config.xml; Connected=OK; Uploaded=OK} @{FTP Server=10.80.59.170; File=test.txt; Connected=OK; Uploaded=OK}