如何在PowerShell中从.dll
或.exe
文件中获取版本信息?
我对File Version
特别感兴趣,尽管还有其他版本信息(即Company
、Language
、Product Name
等)。也会很有帮助。
发布于 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/
发布于 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
发布于 2011-08-06 00:35:25
另一种方法是使用内置的文件访问技术:
(get-item .\filename.exe).VersionInfo | FL
您还可以从VersionInfo获取任何特定属性,如下所示:
(get-item .\filename.exe).VersionInfo.FileVersion
这与dir技术非常接近。
https://stackoverflow.com/questions/30686
复制相似问题