Skip to content

Instantly share code, notes, and snippets.

@cisterni
Last active July 1, 2022 18:08
Show Gist options
  • Save cisterni/23e2d69079ff1f2ebef1c31dc7cf974a to your computer and use it in GitHub Desktop.
Save cisterni/23e2d69079ff1f2ebef1c31dc7cf974a to your computer and use it in GitHub Desktop.
Compute file hash and generate script check
function Get-HashCheck {
[CmdletBinding()]
Param([Parameter(ValueFromPipeline)]$o)
process {
Write-Output "File: $([System.IO.FileInfo]::new($o.Path).Name)"; Write-Output ''
Write-Output ($o | select Algorithm, Hash)
Write-Output ''
Write-Output ('Get-FileHash -Algorithm SHA256 .\' + ([System.IO.FileInfo]::new($o.Path).Name) + ' |% { if ($_.Hash -eq "' + ($o.Hash) + '") { Write-Output "Test $([System.IO.FileInfo]::new($_.Path).Name) OK" } else { Write-Output "Test $([System.IO.FileInfo]::new($_.Path).Name) KO" }}')
}
}
@cisterni
Copy link
Author

cisterni commented Jul 1, 2022

Usage example

Get-FileHash -Algorithm SHA256 myfile.zip | Get-HashCheck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment