MD5 exact column comparison

I have two text file and in this txt files there is an md5 checksums of some backup files. I am trying to compare this text files and if md5 is same I am try to adding near “-2” if it is different adding “-1” but the problem is directories are different that is why when I compare results being always -1. How can I choose exactly MD5 place in the file? Probably if I can change the [System.IO.File]::ReadAllText(‘C:\Users\trerulug\Documents\Inventory1\Inventory.txt’) in the code it can be work. Output :

MD5 C1FA0C20EEFD90076AEFAAB199D854B9 C:\Users\william\Documents\Inventory\12348318433batch.xml

MD5 C1FA0C20EEFD90076AEFAAB199D854B9 C:\Users\william\Documents\Inventory2\12348318433batch.xml,-1

MD5 86CA06D361850A9385CA475E133E4182 C:\Users\william\Documents\Inventory\12348318433batch.xml.xml

MD5 86CA06D361850A9385CA475E133E4182 C:\Users\william\Documents\Inventory2\12348318433batch.xml.xml,-1

MD5 A75515C272B4716FB160DDA644BC9955 C:\Users\william\Documents\Inventory\12348318433batch.xml

MD5 A75515C272B4716FB160DDA644BC9955 C:\Users\william\Documents\Inventory2\12348318433batch.xml,-1

 & {

$ErrorActionPreference = ‘Stop’

$OFS = ‘,’



$To = [System.IO.File]::ReadAllText(‘C:\Users\trerulug\Documents\Inventory1\Inventory.txt’)

$From = & {

if ( -not $To.EndsWith([System.Environment]::NewLine) ) { ‘’ }

Get-Content -Path C:\Users\william\Documents\Inventory2\Inventory.txt |

ForEach-Object { “$($, @(-1, -2)[[int]$To.Contains($)])” }


Add-Content -Path C:\Users\william\Documents\Inventory1\Inventory.txt - Value $From

Get-Content -Path C:\Users\trerulug\Documents\Inventory1\Inventory.txt

} catch {

$_ | Out-String | Write-Warning


Expected Output:

MD5 C1FA0C20EEFD90076AEFAAB199D854B9 C:\Users\william\Documents\Inventory\12348318433batch.xml

MD5 86CA06D361850A9385CA475E133E4182 C:\Users\william\Documents\Inventory2\12348318433batch.xml.xml

MD5 A75515C272B4716FB160DDA644BC9955 C:\Users\william\Documents\Inventory2\12348318433batch.xml

MD5 C1FA0C20EEFD90076AEFAAB199D854B9 C:\Users\william\Documents\Inventory2\12348318433batch.xml,-2

MD5 86CA06D361850A9385CA475E133E4182 C:\Users\william\Documents\Inventory2\12348318433batch.xml.xml,-2

MD5 A75515C272B4716FB160DDA644BC9955 C:\Users\william\Documents\Inventory2\12348318433batch.xml,-2


Could you tell us a bit more about what you’re trying to achieve? Are you looking for a match by MD5 value for any filename or does it need to match both the MD5 and the filename?

Yes I want to match MD5’s from any filenames and the format is like that : MD5 C1FA0C20EEFD90076AEFAAB199D854B9 C:\Users\william\Documents\Inventory\12348318433batch.xml. I can compare MD5’s without directories but I want to compare with directory bu could not do it.

PowerShell or any other language notwithstanding, there is no concept of having a directory in Windows object, only this file objects in it.

So, if you mean you are trying to hash all files in the directory, that is just a loop to get them all individually and hash them.

Encrypting a directory or files or both, sure, but not hashing the directory object. You’d need a 3RdP tool (freeware or paid) for that sort of thing.

For example:

DirHash is a Windows console program that computes the hash of a given directory content or a single file. Recursive Lexicographical order is used for browsing the directory hierarchy so that the computed hash can be seen as unique fingerprint of the target directory. Supported hashing algorithms are MD5, SHA-1, SHA-256, SHA-384, SHA-512 and Streebog.