foreach ($folder1item in $folder1) {
$f1hash = get-filehash $folder1item.fullname
$f2hash = get-filehash ($folder2 | where name -eq ($folder1item.name)).fullname
if ($f2hash.Hash -ne $f1hash.hash) {write-output "$($folder1item).fullname is different to $($folder2item).fullname"}
}
Step1 - Folders To Be Searched
Step2 - Search Both Folders For Files To Be Compared
Step3 - See All Compare Output
Step4 - See Only Difference in reference objects
** Step4a - '=>' - Difference in destination object.
** Step4b - '<=' - Difference in reference (source) object.
** Step4c - '==' - When the source and destination objects are equal.
比较两个文件夹中对象的示例脚本
## Step 1 - Folders To Be Searched
$folder1 = "C:\Temp"
$folder2 = "C:\Test"
## Step 2 - Search Both Folders For Files To Be Compared
$List1 = gci $folder1 -Recurse | Select Name
$List2 = gci $folder2 -Recurse | Select Name
## Step 3 - See All Compare Output
$Compare = Compare-Object -ReferenceObject $List1 -DifferenceObject $List2 -property name -passthru -IncludeEqual
## Step 4 See Only Difference in reference objects
##=> - Difference in destination object.
##<= - Difference in reference (source) object.
##== - When the source and destination objects are equal.
$DifferenceInReference = (Compare-Object -ReferenceObject $List1 -DifferenceObject $List2 | Where SideIndicator -eq "<=")
$DifferenceInReference
$DifferenceInDestination = (Compare-Object -ReferenceObject $List1 -DifferenceObject $List2 | Where SideIndicator -eq "=>")
$DifferenceInDestination
$EqualInBoth = (Compare-Object -ReferenceObject $List1 -DifferenceObject $List2 | Where SideIndicator -eq "==")
$EqualInBoth
3条答案
按热度按时间r7s23pms1#
在windows中,我复制了dirB中的所有文件并在dirA中替换.所有替换的文件将被选中.不单击任何后藤文件夹的主菜单单击反转选择.它可能会有帮助.
vwkv1x7d2#
如果你想比较文件的内容,你可以使用get-filehash来比较哈希值。
比如:
3pvhb19x3#
您可以使用compare-objectcmdlet比较两组对象,一组对象为“引用集”,另一组对象为“差异集”。
使用Compare-Objectcmdlet https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/compare-object?view=powershell-7.2
比较对象的进程
比较两个文件夹中对象的示例脚本