Поделиться через


Server 2012: Using PowerShell to Check for KB2878635

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 (https://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[0]
[version]$DLLVersion = $intFileVer
[version]$Target = "6.2.9200.20712"
$DLLVersion.CompareTo($Target)

For the return values, here's the table from MSDN:

Return value

Meaning

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.