首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >获取PowerShell格式的文件版本

获取PowerShell格式的文件版本
EN

Stack Overflow用户
提问于 2008-08-27 17:28:49
回答 7查看 247.5K关注 0票数 162

如何在PowerShell中从.dll.exe文件中获取版本信息?

我对File Version特别感兴趣,尽管还有其他版本信息(即CompanyLanguageProduct Name等)。也会很有帮助。

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2008-08-27 17:45:54

由于PowerShell可以调用.NET类,因此您可以执行以下操作:

[System.Diagnostics.FileVersionInfo]::GetVersionInfo("somefilepath").FileVersion

或者作为文件列表上的noted here

get-childitem * -include *.dll,*.exe | foreach-object { "{0}`t{1}" -f $_.Name, [System.Diagnostics.FileVersionInfo]::GetVersionInfo($_).FileVersion }

或者更好的脚本:https://jtruher3.wordpress.com/2006/05/14/powershell-and-file-version-information/

票数 163
EN

Stack Overflow用户

发布于 2010-01-29 12:00:09

‘'dir’是Get-ChildItem的别名,当你从具有VersionInfo属性的文件系统中调用它时,它将返回一个System.IO.FileInfo类。所以..。

要获取单个文件的版本信息,请执行以下操作:

PS C:\Windows> (dir .\write.exe).VersionInfo | fl


OriginalFilename : write
FileDescription  : Windows Write
ProductName      : Microsoft® Windows® Operating System
Comments         :
CompanyName      : Microsoft Corporation
FileName         : C:\Windows\write.exe
FileVersion      : 6.1.7600.16385 (win7_rtm.090713-1255)
ProductVersion   : 6.1.7600.16385
IsDebug          : False
IsPatched        : False
IsPreRelease     : False
IsPrivateBuild   : False
IsSpecialBuild   : False
Language         : English (United States)
LegalCopyright   : © Microsoft Corporation. All rights reserved.
LegalTrademarks  :
PrivateBuild     :
SpecialBuild     :

对于多个文件,如下所示:

PS C:\Windows> dir *.exe | %{ $_.VersionInfo }

ProductVersion   FileVersion      FileName
--------------   -----------      --------
6.1.7600.16385   6.1.7600.1638... C:\Windows\bfsvc.exe
6.1.7600.16385   6.1.7600.1638... C:\Windows\explorer.exe
6.1.7600.16385   6.1.7600.1638... C:\Windows\fveupdate.exe
6.1.7600.16385   6.1.7600.1638... C:\Windows\HelpPane.exe
6.1.7600.16385   6.1.7600.1638... C:\Windows\hh.exe
6.1.7600.16385   6.1.7600.1638... C:\Windows\notepad.exe
6.1.7600.16385   6.1.7600.1638... C:\Windows\regedit.exe
6.1.7600.16385   6.1.7600.1638... C:\Windows\splwow64.exe
1,7,0,0          1,7,0,0          C:\Windows\twunk_16.exe
1,7,1,0          1,7,1,0          C:\Windows\twunk_32.exe
6.1.7600.16385   6.1.7600.1638... C:\Windows\winhlp32.exe
6.1.7600.16385   6.1.7600.1638... C:\Windows\write.exe
票数 53
EN

Stack Overflow用户

发布于 2011-08-06 00:35:25

另一种方法是使用内置的文件访问技术:

(get-item .\filename.exe).VersionInfo | FL

您还可以从VersionInfo获取任何特定属性,如下所示:

(get-item .\filename.exe).VersionInfo.FileVersion

这与dir技术非常接近。

票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30686

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档