Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Check damaged Files on an USB Stick and Synchronise if needed

$
0
0

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....

Clear-Host

$path1 = "d:\111\usb"

$path2 = "d:\111\usb2"

$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:\111\usb"

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

 

i get a list of files like this:

Algorithm       Hash                                                                   Path                                                                              

---------       ----                                                                   ----                                                                              

MD5             2B8DF7331B584B24CBFD4306D4A2B390                                       D:\111\usb\Files\PETools64.exe                                                    

MD5             9429168DF9EA582B32A44096A128DC53                                       D:\111\usb\Files\StartNetCustom64.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

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles