Compare logs and extract the difference

Hi Guys, As you know “c:\windows\dpinst.log” is updated whenever you try to install driver using dpinst.exe. I want to extract information of driver which i am installing, not the entire data. I tried the following but it is not extracting the information in correct sequence. Could you help.

$strReference = Get-Content “C:\temp\File\Masterlist.log”
$strDifference = Get-Content “C:\temp\File\ChildList.log”
$a = Compare-Object $strReference $strDifference
a | %{if(.SideIndicator -eq “=>”){
$
.InputObject | out-file “C:\temp\File\new.txt” -Append
}
}

If you want a line by line comparison, then maybe you can try using -SyncWindow 0 on your Compare-Object command.

Hi, I tried the below code, but no luck.
$strReference = Get-Content “C:\temp\File\Masterlist.log”
$strDifference = Get-Content “C:\temp\File\ChildList.log”
$a = Compare-Object $strReference $strDifference -SyncWindow 0
a | %{if(.SideIndicator -eq “=>”){
$
.InputObject | out-file “C:\temp\File\new.txt” -Append
}
}

Output i am getting is not correct.

The way Compare-Object works by default is that it will exhaustively search the reference object for anything in the difference object and vice versa. Adding -SyncWindow attempts to control just how exhaustive that search is. For example, if file1 contains the string Successful Install on line 5 and file2 contains the string Successful Install on line 300, it will be considered a match. -SyncWindow 0 for example would only compare line 5 to line 5 in each file.

Given the above statements, I don’t exactly understand your problem. Is the problem that Compare-Object has the correct differences but outputs them in an order that you don’t like? Or is the problem that Compare-Object seemingly doesn’t output the correct differences? If the problem is the differences, then I can only assume matches are happening elsewhere in the file that you are not considering.

How do you create the files Masterlist.log and Childlist.log? If I got it right I assume you copy the log file before and after an installation. Usually new entries in log files get added at the end. If I got it right you just have to get the line count before and after an installation and you’re almost done. Am I wrong? :wink:

Thanks guys for the reply. I was able to implement. :slight_smile:

So you may share your solution to help others with the same or a similar problem in the future. :wink: