NOTE: This post – drafted, composed, written, and published by me – originally appeared on https://blogs.technet.microsoft.com/johnbai and is potentially (c) Microsoft.
In the course of an investigation, it became necessary to write a PowerShell script to check the current file version of the kernelbase.dll. I needed to compare it against the file version of a KB that was pushed for better resiliency (http://support.microsoft.com/kb/2878635).
The script uses some basic logic to get the file version and compare it with the known published version of the file, at the time the KB was published, and determine if we were below, at, or above that file version. I’m including links to the MSDN articles that helped me to write the script.
$FileVer = ([System.Diagnostics.FileVersionInfo]::GetVersionInfo(“C:\Windows\System32\kernelbase.dll”)).FileVersion
$pattern = ” ”
$intVer = [Regex]::Split($FileVer,$pattern)
$intFileVer = $intVer
[version]$DLLVersion = $intFileVer
[version]$Target = “6.2.9200.20712”
For the return values, here’s the table from MSDN:
|Less than zero||The current Version object is a version before value.|
|Zero||The current Version object is the same version as value.|
|Greater than zero||The current Version object is a version subsequent to value.|