我想输出线,以我的.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