I created a function to get the hash value of a file. Normally the output is 3 lines. My function does 3 things:
- extracts the hash value
- removes the spaces in between the hash value
- prints hash value
Here is the output when using CertUtil -hashfile FILENAME.EXE SHA1
SHA1 hash of file FILENAME.EXE:
XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
CertUtil: -hashfile command completed successfully.
My function:
function MyHash($file, $hashtype) {
$hash = CertUtil -hashfile $file $hashtype
$hashstring = $hash[1] -replace ' ',''
echo $hashstring
}
my output:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Am I ok calling commands such as CertUtil
from within a function the way I am doing? Can the syntax and code be improved? I feel like I'm just throwing commands inside a function but it works.