Created
January 28, 2020 08:23
-
-
Save deviousasti/041d5298adf9a23e7700b7ff5460ce0b to your computer and use it in GitHub Desktop.
Simple File Integrity Verifier in Powershell
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
| 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] } } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
Drop it in your PowerShell modules directory in
Verify\Verify.psm1.In any folder, use
Create-Verificationto generate
(current folder).sha2The defaults are:
To verify, use:
-Pathand-Filteroptions still apply.