Last active
January 24, 2020 20:33
-
-
Save kevinCefalu/2bf8691742a9a3bcd3b2810627889b37 to your computer and use it in GitHub Desktop.
A function to calculate hashes on files, using one or more algorithm types.
This file contains 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 Get-MultiFileHash | |
{ | |
[CmdletBinding(DefaultParameterSetName = 'Path')] | |
param ( | |
[Parameter( | |
Mandatory, | |
ParameterSetName = 'Path' | |
)] | |
[string[]] $Path, | |
[Parameter( | |
Mandatory, | |
ParameterSetName = 'LiteralPath', | |
ValueFromPipelineByPropertyName | |
)] | |
[Alias("PSPath")] | |
[string[]] $LiteralPath, | |
[Parameter( | |
Mandatory, | |
ParameterSetName = 'Stream' | |
)] | |
[IO.Stream] $InputStream, | |
[Parameter()] | |
[ValidateSet( | |
'SHA1', 'SHA256', 'SHA384', 'SHA512', | |
'MACTripleDES', 'MD5', 'RIPEMD160' | |
)] | |
[string[]] $Algorithm = 'SHA256' | |
); | |
begin | |
{ | |
$Output = [Collections.Generic.List[PSCustomObject]]::new(); | |
} | |
process | |
{ | |
foreach ($Alg in $Algorithm) | |
{ | |
$PSBoundParameters['Algorithm'] = $Alg; | |
$Output.Add((Get-FileHash @PSBoundParameters)); | |
} | |
} | |
end | |
{ | |
Write-Host; | |
$Output ` | |
| Group-Object -Property Path ` | |
| ForEach-Object ` | |
{ | |
Write-Host "File: $($_.Name)"; | |
$_.Group ` | |
| Select-Object ` | |
-Property Algorithm, Hash ` | |
| Out-String ` | |
| Write-Host; | |
}; | |
return $Output; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment