Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell get-item VersionInfo.ProductVersion incorrect / different than WMI

I'm trying to understand why Powershell would get back a different version number for a DLL file than what both the file properties page from Windows Explorer, and a WMI query shows. (I apologize in advance if this doesn't correctly qualify as a coding question.)

The scenario:

Running the following powershell command:

(get-item C:\windows\system32\rdpcorekmts.dll).VersionInfo.ProductVersion

This returns the following:

6.1.7600.16385

However, this version number is incorrect. When examining the version information from Windows Explorer, you see the following version (sorry, I tried posting a small screenshot of it, but I don't have enough rep; I'm new here):

6.1.7601.17767

In addition, a WMIC query shows the same results as Windows Explorer:

WMIC path CIM_DataFile WHERE (name="c:\\windows\\system32\\rdpcorekmts.dll") get Version

WMIC result:

Version

6.1.7601.17767

I really don't understand why they would be different. I would really like to return this value using Powershell, but now I'm not sure if I'm just overlooking something, or if I ran across some kind of odd bug, but the version mismatch between the two methods is confusing. As a note, I've run variations on the method to get this back in Powershell (e.g. Get-ItemChild and Get-ItemProperty), and I get the same incorrect version result.

Any ideas on why?

like image 551
jschleicher Avatar asked Jun 18 '12 20:06

jschleicher


People also ask

Does PowerShell use WMI?

Windows PowerShell implements WMI functionality through a set of cmdlets that are available in Windows PowerShell by default. You can use these cmdlets to complete the end-to-end tasks necessary to manage local and remote computers. The following WMI cmdlets are included. about the available classes.

How do I get the version of a file in PowerShell?

You can get file version of file using PowerShell Get-Command cmdlet. In the above command, Get-Command get dll assembly file version of the specified file using FileVersionInfo. FileVersion property.

How do you get Windows instrumentation management details in PowerShell?

The Get-WmiObject cmdlet gets instances of WMI classes or information about the available WMI classes. To specify a remote computer, use the ComputerName parameter. If the List parameter is specified, the cmdlet gets information about the WMI classes that are available in a specified namespace.

How do I run a WMI query in PowerShell?

So how do you use the WQL query to retrieve information from a system? In Windows PowerShell 2.0, there are two main ways to do this. The first is to use the Get-WmiObject cmdlet, and the second is to use the [wmisearcher] type accelerator. The [wmisearcher] type accelerator creates a ManagementObjectSearcher class.


1 Answers

The problem is that you are using the ProductVersion propertie which seems to be hard coded somewhere, IE and WMI are just buildind the product version from :

ProductMajorPart   : 6
ProductMinorPart   : 1
ProductBuildPart   : 7601
ProductPrivatePart : 17767

Same for FileVersion with : FileMajorPart, FileMinorPart, FileBuildPart, FilePrivatePart

Just try :

(get-item C:\windows\system32\rdpcorekmts.dll).VersionInfo | fl *

You can test :

(get-item C:\windows\system32\rdpcorekmts.dll).VersionInfo | % {("{0}.{1}.{2}.{3}" -f $_.ProductMajorPart,$_.ProductMinorPart,$_.ProductBuildPart,$_.ProductPrivatePart)}

From CMD.EXE you can try :

C:\>powershell -command "&{(get-item C:\windows\system32\rdpcorekmts.dll).VersionInfo | % {write-host ('{0}.{1}.{2}.{3}' -f $_.ProductMajorPart,$_.ProductMinorPart,$_.ProductBuildPart,$_.ProductPrivatePart)}}"
like image 67
JPBlanc Avatar answered Sep 21 '22 15:09

JPBlanc