I have another script that outputs data into a csv file every 4 hours and creates the files as vdsinfo_$(Get-Date -Format "yyMMdd_hh-mm-ss").csv.
I want to be able to compare the original file created and also the last two files created against each other to see if there has changes within the file.
At the moment, this is what I have for the script but it isn't quite there yet and would really appreciate some help to get this producing an output written to a Changes.csv file.
I want to compare files that file names are always changing so the script needs to be using variables where possible and only way I can see this working is by the get-date addhours-4.
$File = 'E:\TEMP\Changes.csv'
# Get File item
$file1 = Get-ChildItem -Path E:\TEMP\reports\vdsinfo_original.csv
# Get the specific date
$date1 = (Get-Date).AddHours(-8)
# Compare file modified date with specific date
$file2 = $file1.LastWriteTime -gt $date1
Compare-Object -ReferenceObject $file1 -DifferenceObject $file2 -CaseSensitive | Format-table InputObject, SideIndicator -Autosize | out-file $file -Width 200
Else {
Write-Host "File missing " -ForegroundColor White -BackgroundColor Red
}
Any help would really help me, thanks in advance
With this current script it only does comparison against two files and I'd like to compare against the original and the last two files within the folder location.
This is a bit unclear, but in the following I'm going to assume you want to generate 2 sets of changes:
That's not necessary at all. The file name contains a sortable date/timestamp, so sort the files by name, then you can simply jump to the previous file in your sorted list and get the data from 4 hours prior: