Get-FileHash无法按预期工作

时间:2018-01-22 14:14:13

标签: powershell

我正在尝试使用 GatewayDiscoveryClientAutoConfiguration#discoveryClientRouteDefinitionLocator: Did not match: - @ConditionalOnBean (types: org.springframework.cloud.client.discovery.DiscoveryClient; SearchStrategy: all) did not find any beans of type org.springframework.cloud.client.discovery.DiscoveryClient (OnBeanCondition) Matched: - @ConditionalOnProperty (spring.cloud.gateway.discovery.locator.enabled) matched (OnPropertyCondition) 检查针对哈希数组的文件MD5哈希。考虑一下这个简单的代码:

Get-FileHash
总是返回“不匹配”,但我可以手动验证哈希是否正确:

$dir = Get-ChildItem -Recurse 'C:\Files'

$md5hash = @(
'6edaaec9c5b9cea3f035065d7283ca07', 
'023c80233d32b33128841038491af8c7',
'f58d26a3fe697efd84c2a841140bc524')

$dir | ForEach-Object { 
    if ($md5hash -contains (Get-FileHash $_.FullName -Algorithm MD5)) 
    {
        Write-Output "Match found." 
    } 
    else 
    {
        Write-Output "No match.
    }
}

代码有什么问题?

1 个答案:

答案 0 :(得分:3)

Get-FileHash不返回字符串,而是返回一个对象,只需运行一次即可轻松验证:

PS> Get-FileHash test.txt -Algorithm md5

Algorithm Hash                             Path
--------- ----                             ----
MD5       B53F079809559E4E8C2B13863B153ABF Home:\test.txt

所以,将代码更改为

$md5hash -contains (Get-FileHash $_ -Algorithm MD5).Hash
相关问题