我想輸出線,以我的.txt文件/日誌文件,基本上抓住的$source
的路徑,然後說:「相比太」的$compare
路徑。但是當我用Out-File
這樣做時,它們會互相覆蓋。舉例來說,如果我只是在遞歸之前執行$source | Out-File $log
,那麼下一個Out-File
會寫入它。所以,當我看完我的日誌時,腳本的末尾就是我在下面使用的Compare-Object | Out-File $log
。Powershell的多張變量到Out-文件
#prompts user for input through cmd for path of log file
$log = Read-Host -Prompt 'Input path of log, if log does not, create one. Include file name and extension'
#prompts user for input through cmd, saves path, then recursively searches
$source = Read-Host -Prompt 'Input source path'
$source = gci $source -recurse
#prompts user for input through cmd, saves path, then recursively searches
$compare = Read-Host -Prompt 'Input the path of directory to compare'
$compare = gci $compare -recurse
#compares the $source to the $compare and outputs to log file
Compare-Object -ReferenceObject $source -DifferenceObject $compare -PassThru | Out-File $log -width 120
謝謝,不知道我是如何忽略這一點的。 – user6124417
沒問題,如果它回答了你的問題,你能接受答案嗎? – Richard