Skip to content

Instantly share code, notes, and snippets.

@deviousasti
Created January 28, 2020 08:23
Show Gist options
  • Save deviousasti/041d5298adf9a23e7700b7ff5460ce0b to your computer and use it in GitHub Desktop.
Save deviousasti/041d5298adf9a23e7700b7ff5460ce0b to your computer and use it in GitHub Desktop.
Simple File Integrity Verifier in Powershell
function Create-Verification {
param([string] $Path = ".", [string] $Verify = "", [string] $Filter = "*.*")
$Output = "$($Path | Split-Path -Leaf).sha2"
$Table =
Get-ChildItem -Path $Path |
Where-Object { $_.Name -like $Filter -and $_.Name -ne $Output } | #Don't inculde the .sha2 file
Sort-Object -Property Name |
Get-FileHash -Algorithm SHA256 |
Format-Table @{ Label = 'File'; Expression = { $_.Path | Split-Path -Leaf }}, Hash |
Out-String -Stream
if($Verify -eq "") {
$Table | Out-File $Output
Get-Content $Output
}
else {
Compare-Object ($Table | Select-Object -Skip 3) (Get-Content $Verify | Select-Object -Skip 3) |
Where-Object { $_ -ne $null } |
Select-Object @{ Name = "Side"; Expression = { $_.SideIndicator } }, @{Name = "File"; Expression = { $_.InputObject.Split(' ')[0] } }
}
}
@deviousasti
Copy link
Author

Usage

Drop it in your PowerShell modules directory in Verify\Verify.psm1.

In any folder, use

Create-Verification

to generate (current folder).sha2

The defaults are:

Create-Verification -Path . -Filter *.*

To verify, use:

Create-Verification -Verify (folder.sha2) 

-Path and -Filter options still apply.

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