Hi everyone! I’m new here as well as new to Powershell but I could really use some help here.
I need to export the MD5 hashes of two directories and match them. When exporting the MD5 hashes in a CSV file, it creates three columns: Algorithm, Hash and Path where Path displays the full path (C:\Users\Admin\Desktop\ExampleFiles\SampleFile.dll for example). I want to change that and make it so that only two columns are created: Hash and File Name. Where Path displays the full path (C:\Users\Admin\Desktop\ExampleFiles\SampleFile.txt for example). However, I want it to only display the name of the file (SampleFile.txt).
If there are files inside more folders then I want it to look like this (TestFolder1\File1.txt) and not (C:\Users\Admin\Desktop\ExampleFiles\TestFolder1\File1.txt). Please note that in this case, the “ExampleFiles” folder is the folder that I want to deal with and I want to store all the MD5 hashes of all the files in it.
For now, the code that I have is this:
#Getting the MD5 hash of the source and storing it a csv format
$SourcePath = Get-ChildItem -Path 'C:\source\Folder1' -Recurse
$SourceHash = foreach ($File in $InstallerPath)
{
Get-FileHash $File.FullName -Algorithm MD5 -ErrorAction SilentlyContinue
}
$SourceHash | Export-Csv -Path C:\Users\Admin\Desktop\Exports\SourceHash.csv
#Getting the MD5 hash of the destination and storing it in a csv format
$DestinationPath = Get-ChildItem -Path "C:\destination\Folder1" -Recurse
$DestinationHash = foreach ($File in $DestinationPath)
{
Get-FileHash $File.FullName -Algorithm MD5 -ErrorAction SilentlyContinue
}
$DestinationHash | Export-Csv -Path C:\Users\Admin\Desktop\Exports\DestinationHash.csv
In the exported CSV file, I can see that three columns have been created: Algorithm, Hash and Path. I’ve tried using Select-Object -Property FullName, Hash and piping it into Export-Csv but that doesn’t work since the $DestinationHash and $SourceHash do not contain the FullName of the files, only the paths.
I want the CSV to look like this:
| Hash | FileName |
| 87654897XYZABCD | SampleFile.txt |
| XYZABCD87654897 | TestFolder1\File1.txt |