I'm quite new to Powershell so please excuse my inexperience or lack of best practices. I am writing a script that will first store the MD5 hashes of two different directories in a CSV format. I then want to compare the two files and if there are any changes in the two CSV files (i.e the MD5 hash of a file doesn't match or one file in the source folder's CSV file is absent from the destination folder's CSV file), I want to generate a new list with the details of the mismatched or absent files.
In addition to this, I was wondering if there is a faster way of comparing the two files because the folder that I am dealing with is quite large and has about 12k files in it. I was thinking that maybe I'd try to keep the source CSV intact and remove the entries from the destination CSV one by one as they are checked and verified. Can anyone please help me with this?
#Getting the MD5 hash of the Installer and storing it a csv format
$SourcePath = Get-ChildItem -Path C:\source -Recurse
$SourcerHash = foreach ($File in $SourcePath)
{
Get-FileHash $File.FullName -Algorithm MD5
}
$SourceHash | Export-Csv -Path C:\Users\abcd\Desktop\CSVExports\SourceHash.csv
#Getting the MD5 hash of the destination directory and storing it in a csv format
$DestinationPath = Get-ChildItem -Path C:\destination -Recurse
$DestinationHash = foreach ($File in $DestinationPath)
{
Get-FileHash $File.FullName -Algorithm MD5
}
$DestinationHash | Export-Csv -Path C:\Users\abcd\Desktop\CSVExports\DestinationHash.csv
#Comparing the hashes of Installer and Destination directories
Compare-Object -ReferenceObject (Import-Csv C:\Users\abcd\Desktop\CSVExports\InstallerHash.csv) -DifferenceObject (Import-Csv C:\Users\abcd\Desktop\CSVExports\DestinationHash.csv) -Property Hash | Export-Csv C:\Users\abcd\Desktop\CSVExports\ResultTable