Skip to content

Instantly share code, notes, and snippets.

@77Z
Created December 13, 2024 17:42
Show Gist options
  • Select an option

  • Save 77Z/dfe24213068d43f0f8b77eff7350ea40 to your computer and use it in GitHub Desktop.

Select an option

Save 77Z/dfe24213068d43f0f8b77eff7350ea40 to your computer and use it in GitHub Desktop.
# Define the path to start searching and the checksum to match
$path = "C:\Path\To\Directory"
$expectedChecksum = "your_expected_checksum_here"
# Function to calculate the checksum of a file
function Get-FileChecksum {
param (
[string]$filePath
)
$hashAlgorithm = [System.Security.Cryptography.HashAlgorithm]::Create("SHA256")
$fileStream = [System.IO.File]::OpenRead($filePath)
$checksum = $hashAlgorithm.ComputeHash($fileStream)
$fileStream.Close()
return [BitConverter]::ToString($checksum) -replace "-", ""
}
# Iterate through each file in the directory and its subdirectories
Get-ChildItem -Path $path -Recurse -File | ForEach-Object {
$file = $_.FullName
$checksum = Get-FileChecksum -filePath $file
if ($checksum -eq $expectedChecksum) {
Write-Output "Match found: $file"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment