Check damaged Files on an USB Stick and Synchronise if needed

by May 27, 2015

Hi there

i´ve wrote already in the subject what my goal is.

At the moment i´ve not yet reached my goal because i don't understand the behavior….


$path1 = "d:111usb"

$path2 = "d:111usb2"

$Hash1 = Get-ChildItem -File -Recurse -Path $path1 | Get-FileHash -Algorithm MD5

$Hash2 = Get-ChildItem -File -Recurse -Path $path1 | Get-FileHash -Algorithm MD5


Write-Host $hash1.hash >> hash1.txt

Write-Host $hash2.hash >> hash1.txt


if ($hash1.hash -eq $hash2.hash) {Write-Host equal}

else {Write-Host not equal}

At the moment there are only two files in this directory – and this is the result:

2B8DF7331B584B24CBFD4306D4A2B390 9429168DF9EA582B32A44096A128DC53

2B8DF7331B584B24CBFD4306D4A2B390 9429168DF9EA582B32A44096A128DC53

not equal

PS D:111> 

The Write-Host-Command is only for me to see whats happening.

Well – for me the strings are equal – but why i get returned "not equal"?

And i have an second question: If i simplify it a little bit:

$path1 = "d:111usb"

Get-ChildItem -File -Recurse -Path $path1 | Get-FileHash -Algorithm MD5

i get a list of files like this:

Algorithm       Hash                                                                   Path                                                                              

———       —-                                                                   —-                                                                              

MD5             2B8DF7331B584B24CBFD4306D4A2B390                                       D:111usbFilesPETools64.exe                                                    

MD5             9429168DF9EA582B32A44096A128DC53                                       D:111usbFilesStartNetCustom64.cmd  

But if get-filehash is piped its only one line with the hash-values. How can i get this in a table form? | ft is not working