Compare a copied file with SHA256
Documentation: Microsoft Learn
Get-FileHash reads each file using SHA256. LiteralPath treats brackets in filenames literally.
The script
Script reader
Inspect before you run
Inspect the script below. It does not run in this browser.
Inspection only — no command has run.
Show reference output
Inspect this example’s structure
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
$sourceHash = Get-FileHash -LiteralPath '.\source.txt' -Algorithm SHA256 -ErrorAction Stop
$copyHash = Get-FileHash -LiteralPath '.\copy.txt' -Algorithm SHA256 -ErrorAction Stop
[pscustomobject]@{
SourceHash = $sourceHash.Hash
CopyHash = $copyHash.Hash
Match = $sourceHash.Hash -eq $copyHash.Hash }- Stage 1$sourceHash
Positional values or no named parameters
How it works
Get-FileHash reads each file using SHA256. LiteralPath treats brackets in filenames literally. ErrorAction Stop prevents a failed file read from continuing into a misleading comparison. The report retains both hash strings and a Boolean Match value.
Adapting it
Replace the two file paths with the source and copy you intend to compare. Keep both files stable during the check and use the same hash algorithm for both.