Replace Get-FileHash with MD5 code that works on PowerShell 3.
This commit is contained in:
parent
6e7773e9b8
commit
1b6ef9aa2e
1 changed files with 17 additions and 14 deletions
|
@ -34,27 +34,30 @@ $result = New-Object psobject @{
|
||||||
|
|
||||||
If (Test-Path $path)
|
If (Test-Path $path)
|
||||||
{
|
{
|
||||||
Set-Attr $result.stat "exists" $TRUE;
|
Set-Attr $result.stat "exists" $TRUE;
|
||||||
$info = Get-Item $path;
|
$info = Get-Item $path;
|
||||||
If ($info.Directory) # Only files have the .Directory attribute.
|
If ($info.Directory) # Only files have the .Directory attribute.
|
||||||
{
|
{
|
||||||
Set-Attr $result.stat "isdir" $FALSE;
|
Set-Attr $result.stat "isdir" $FALSE;
|
||||||
Set-Attr $result.stat "size" $info.Length;
|
Set-Attr $result.stat "size" $info.Length;
|
||||||
}
|
}
|
||||||
Else
|
Else
|
||||||
{
|
{
|
||||||
Set-Attr $result.stat "isdir" $TRUE;
|
Set-Attr $result.stat "isdir" $TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Else
|
Else
|
||||||
{
|
{
|
||||||
Set-Attr $result.stat "exists" $FALSE;
|
Set-Attr $result.stat "exists" $FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
If ($get_md5 -and $result.stat.exists -and -not $result.stat.isdir)
|
If ($get_md5 -and $result.stat.exists -and -not $result.stat.isdir)
|
||||||
{
|
{
|
||||||
$path_md5 = (Get-FileHash -Path $path -Algorithm MD5).Hash.ToLower();
|
$sp = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider;
|
||||||
Set-Attr $result.stat "md5" $path_md5;
|
$fp = [System.IO.File]::Open($path, [System.IO.Filemode]::Open, [System.IO.FileAccess]::Read);
|
||||||
|
$hash = [System.BitConverter]::ToString($sp.ComputeHash($fp)).Replace("-", "").ToLower();
|
||||||
|
$fp.Dispose();
|
||||||
|
Set-Attr $result.stat "md5" $hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
Exit-Json $result;
|
Exit-Json $result;
|
||||||
|
|
Loading…
Reference in a new issue