PowerShell:通过Hash比较文件夹

时间:2013-09-20 06:38:32

标签: file powershell hash directory copying

在为所有文件生成哈希值之后,我正在尝试验证文件夹中的文件。

我可以成功获得Hash输出,但是我在解决这个问题时遇到了问题。

# Compare the files inside both folders togethor

$Results = @( Compare-Object -ReferenceObject $( Hash-Folder -Folder $FolderSource ) -DifferenceObject $( Hash-Folder -Folder $FolderDestination ) -Property Name, Hash -IncludeEqual:$False | Sort-Object -Unique | Format-Table -HideTableHeaders | Out-String -Stream -Width 125 )

#If there are no differences, all is ok
If ( $Results -eq $NULL ) {

                Write-host "All files verified successfully"

            { Else {

                # There must be some differences, which side?

                ForEach ( $Result in $Results ) {

                    If ( $Result.SideIndicator -eq '<=' ) {

                    Write-Host "This file is different in the source " $Result.Trim()

                    }

                    If ( $Result.SideIndicator -eq '=>' ) {

                    Write-Host "This file is different in the destination " $Result.Trim()

                    }

                }

            }

        }                

0 个答案:

没有答案