Created
December 13, 2024 17:42
-
-
Save 77Z/dfe24213068d43f0f8b77eff7350ea40 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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