PowerShell Find File With FileHash (比對 FileHash 搜尋檔案)


  1. 說明
  2. 相關連結

說明如何使用 PowerShell 迭代查詢資料夾檔案中符合特定 FileHash 的檔案。

logo

說明

使用 PowerShell ISE 執行下列指令:

$targetHash = "E3E5198F5643285615E25B6A2321ADA143FE12E10CF061E327AEEA8F689AA6F6"
Get-ChildItem -Path "C:\Documents" -Filter *.jpg -Recurse | ForEach-Object {
  $hash = (Get-FileHash $_.FullName).Hash
  if ($hash -eq $targetHash) {
    $_.FullName
  }
}

One Line Version 😎

Get-ChildItem -Path "C:\Documents" -Filter *.jpg -Recurse | ? { (Get-FileHash $_.FullName).Hash -eq $targetHash } | Select FullName

相關連結

PowerShell 使用者不能錯過的 5 個技巧

Powershell 使用物件與資料結構 (Array, Hash)

PowerShell 常用指令筆記