Mam kod:
function Get-Hash($algorithm, $file)
{
$algo=[System.Security.Cryptography.HashAlgorithm]::Create($algorithm)
if ($algo)
{
$Fc = gc $file
$Encoding = New-Object System.Text.ASCIIEncoding
$Bytes = $Encoding.GetBytes($Fc)
$Hash = $Algo.ComputeHash($Bytes)
$hashstring = ""
foreach ($byte in $hash)
{
$hashstring += $byte.tostring("x2")
}
return $hashstring
}
}
function New-HashObject($file, $hash)
{
$out = New-Object PSObject
$out | add-member noteproperty File (Get-Filename $file)
$out | add-member noteproperty Hash $hash
return $out
}
function Get-SHA1hash
{
foreach ($file in $args)
{
$hashObject = New-HashObject $file (Get-Hash SHA1 $file)
$results += ,$hashObject
}
$results
}
I jak przeładować matodę ToString()
dla HashObject tak by przy użyciu Write-Host (Get-SHA1hash "jakis_tam_plik")[0])
wyświetlił się sam hash?