Reputation: 81
I have two files in the same directory I wish to compare hashes, Release.zip and release821hash.txt
The first command I have to use is get-filehash Release.zip -a md5
The second command I have to use is get-content release821hash.txt
I then have to use the -eq to compare hashes, as defined per lab requirements:
1. Type "new hash" -eq "known hash" and press Enter to determine whether the
file hashes match.
■ The new hash is the hash generated by the get-filehash file_name -a
md5 command.
■ The known hash is the hash generated by the get-content
file_name.txt command.
■ Include the quotation marks and the file extensions with the file names
in the commands.
However my powershell throws an error. I have tried using every possible way to compare using -eq but it constantly throws errors. What am I doing wrong? I have tried using no quotation, quotations just around the "get" commands, and using one quotation for the entire line.
Upvotes: 5
Views: 12007
Reputation: 1
To check do the comparison just type the following
"4A84C7958C246E39439C784349F4ZDB4" -eq "9C784349F4ZDB44A84C7958C246E3943"
Upvotes: -2
Reputation: 1
You have to put the actual hash in the command line. Example: "4A84C7958C246E39439C784349F4ZDB4" -eq "9C784349F4ZDB44A84C7958C246E3943"
Upvotes: -1
Reputation: 58431
Get-FileHash
returns an object containing, among other things, the hash.
To get the actual hash, you'll have use the Hash
property of the object.
So you could do
$fileHash = (Get-FileHash Release.zip -a md5).Hash
Get-Content
might return a single string but it also might return an array of strings, depending on newlines being present in the file you are reading. Assuming the file only contains a hash, following might suffice
$checkHash = Get-Content release821hash.txt
Stitching both together, your check could be
$fileHash -eq $checkHash
or
((Get-FileHash Release.zip -a md5).Hash) -eq (Get-Content release821hash.txt)
Note: if you know the hashes to be equal but the check returns false, most likely there are additional characters in the release821hash.txt file and you'll have to strip those from the string.
Upvotes: 7