powershell - Powershell get-Itemm VersionInfo.ProductVersion错误/与WMI不同

标签 powershell wmi-query wmic versioninfo

我试图理解为什么Powershell会为DLL文件获取与Windows资源管理器中的文件属性页和WMI查询都不同的版本号。 (如果不正确地将其视为编码问题,我谨此致歉。)
场景:
运行以下powershell命令:

(get-item C:\windows\system32\rdpcorekmts.dll).VersionInfo.ProductVersion
这将返回以下内容:

6.1.7600.16385


但是,此版本号不正确。从Windows资源管理器检查版本信息时,您会看到以下版本(对不起,我尝试发布它的一个小屏幕截图,但是我没有足够的代表;这是我的新手):

6.1.7601.17767


此外,WMIC查询显示的结果与Windows资源管理器相同:
WMIC path CIM_DataFile WHERE (name="c:\\windows\\system32\\rdpcorekmts.dll") get Version
WMIC结果:

Version

6.1.7601.17767


我真的不明白为什么他们会有所不同。我真的很想使用Powershell返回此值,但是现在我不确定是否只是在忽略某些内容,还是遇到某种奇怪的错误,但是这两种方法之间的版本不匹配令人困惑。请注意,我在方法上运行了各种变体以将其恢复到Powershell中(例如Get-ItemChild和Get-ItemProperty),并且得到了相同的错误版本结果。
有什么想法吗?

最佳答案

问题是您正在使用ProductVersion属性,该属性似乎在某处进行了硬编码,IE和WMI只是buildind产品版本,来自:

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

FileVersion相同,具有:FileMajorPart,FileMinorPart,FileBuildPart,FilePrivatePart

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

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

从CMD.EXE,您可以尝试:
C:\>powershell -command "&{(get-item C:\windows\system32\rdpcorekmts.dll).VersionInfo | % {write-host ('{0}.{1}.{2}.{3}' -f $_.ProductMajorPart,$_.ProductMinorPart,$_.ProductBuildPart,$_.ProductPrivatePart)}}"

关于powershell - Powershell get-Itemm VersionInfo.ProductVersion错误/与WMI不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11090875/

相关文章:

python - 使用Python在远程主机中创建目录

远程计算机上的 Delphi Wmi 查询

PowerShell计算错误

powershell - 从 pscustomobject 的单列格式化哈希表

带有 -RepetitionInterval 的 Powershell New-ScheduledTaskTrigger 重复任务

c++ - 通过 MSFT_NetAdapter 启用/禁用网络适配器

c# - "The RPC server is unavailable"使用 WMI 查询

Unix 中无法识别 Java WMIC 命令

apache-kafka - 无法使用 .\bin\windows\kafka-server-start.bat .\config\server.properties cmd 启动 kafka

powershell - 从PowerShell脚本设置Octopus参数