How can you get the version information from a .dll or .exe file in PowerShell?
Specifically interested in File Version, though other version info (i.e. Company, Language, Product Name, etc) would be helpful as well.
How can you get the version information from a .dll or .exe file in PowerShell?
Specifically interested in File Version, though other version info (i.e. Company, Language, Product Name, etc) would be helpful as well.
[System.Diagnostics.FileVersionInfo]::GetVersionInfo("Path\To\File.dll")
Since PowerShell can call .Net classes you could do the following:
[System.Diagnostics.FileVersionInfo]::GetVersionInfo("somefilepath").FileVersion
Or as noted here on a list of files:
get-childitem * -include *.dll,*.exe | foreach-object { "{0}`t{1}" -f $_.Name, [System.Diagnostics.FileVersionInfo]::GetVersionInfo($_).LegalCopyright }
Or even nicer as a script: http://jtruher.spaces.live.com/blog/cns!7143DA6E51A2628D!125.entry
As EBGreen said, [System.Diagnostics.FileVersionInfo]::GetVersionInfo(path) will work, but remember that you can also get all the members of FileVersionInfo, for example:
[System.Diagnostics.FileVersionInfo]::GetVersionInfo(path).CompanyName
You should be able to use every member of FileVersionInfo documented here, which will get you basically anything you could ever want about the file.
I prefer to install the PowerShell Community Extensions and just use the Get-FileVersionInfo function that it provides.
Like so:
Get-FileVersionInfo MyAssembly.dllwith output like:
ProductVersion FileVersion FileName -------------- ----------- -------- 1.0.2907.18095 1.0.2907.18095 C:\Path\To\MyAssembly.dll
I've used it against an entire directory of assemblies with great success.
Try using the built-in command instead:
(Get-Command C:\Path\YourFile.Dll).FileVersionInfo
or
dir *.dll,*.exe | %{gcm $_.FullName} | select -expand File*
These only get the first 3 parts of the file version... ex: 1.9.2 instead of 1.9.2.1234
'dir' is an alias for Get-ChildItem which will return back a System.IO.FileInfo class when you're calling it from the filesystem which has VersionInfo as a property. So ...
To get the version info of a single file do this:
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 :
For multiple files this:
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