Last active
November 18, 2024 08:38
-
-
Save jahands/fd5a2db41d308e83ba6d to your computer and use it in GitHub Desktop.
Get hash of entire directory 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 Get-DirHash { | |
[Cmdletbinding()] | |
Param( | |
[Parameter(Mandatory=$true)] | |
[ValidateScript({ | |
if(Test-Path -Path $_ -ErrorAction SilentlyContinue) | |
{ | |
return $true | |
} | |
else | |
{ | |
throw "$($_) is not a valid path." | |
} | |
})] | |
[string]$Path | |
) | |
$temp=[System.IO.Path]::GetTempFileName() | |
gci -File -Recurse $Path | Get-FileHash | select -ExpandProperty Hash | Out-File $temp -NoNewline | |
$hash=Get-FileHash $temp | |
Remove-Item $temp | |
$hash.Path=$Path | |
return $hash | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You don't need a temp file if you use MemoryStreams:
$temp = gci -File -Recurse $Path | Get-FileHash | select -ExpandProperty Hash | Out-String
$hash = Get-FileHash -InputStream ([IO.MemoryStream]::new([char[]]$temp))