How can you get the version information from a .dll
or .exe
file in PowerShell?
I am specifically interested in File Version
, though other version information (that is, 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?
I am specifically interested in File Version
, though other version information (that is, Company
, Language
, Product Name
, etc.) would be helpful as well.
Just another way to do it is to use the built-in file access technique:
You can also get any particular property off the VersionInfo, thus:
This is quite close to the dir technique.
Since PowerShell can call .NET classes, you could do the following:
Or as noted here on a list of files:
Or even nicer as a script: https://jtruher3.wordpress.com/2006/05/14/powershell-and-file-version-information/
As EBGreen said, [System.Diagnostics.FileVersionInfo]::GetVersionInfo(path) will work, but remember that you can also get all the members of FileVersionInfo, for example:
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 realise this has already been answered, but if anyone's interested in typing fewer characters, I believe this is the shortest way of writing this in PS v3+:
ls
is an alias forGet-ChildItem
%
is an alias forForEach-Object
versioninfo
here is a shorthand way of writing{$_.VersionInfo}
The benefit of using
ls
in this way is that you can easily adapt it to look for a given file within subfolders. For example, the following command will return version info for all files calledapplication.exe
within subfolders:-r
is an alias for-Recurse
You can further refine this by adding
-ea silentlycontinue
to ignore things like permission errors in folders you can't search:-ea
is an alias for-ErrorAction
Finally, if you are getting ellipses (...) in your results, you can append
| fl
to return the information in a different format. This returns much more detail, although formatted in a list, rather that on one line per result:fl
is an alias forFormat-List
I realise this is very similar to xcud's reply in that
ls
anddir
are both aliases forGet-ChildItem
. But I'm hoping my "shortest" method will help someone.The final example could be written in long-hand in the following way:
... but I think my way is cooler and, for some, easier to remember. (But mostly cooler).
Nowadays you can get the FileVersionInfo from Get-Item or Get-ChildItem, but it will show the original FileVersion from the shipped product, and not the updated version. For instance:
Interestingly, you can get the updated (patched) ProductVersion by using this:
The distinction I'm making between "original" and "patched" is basically due to the way the FileVersion is calculated (see the docs here). Basically ever since Vista, the Windows API GetFileVersionInfo is querying part of the version information from the language neutral file (exe/dll) and the non-fixed part from a language-specific mui file (which isn't updated every time the files change).
So with a file like lsasrv (which got replaced due to security problems in SSL/TLS/RDS in November 2014) the versions reported by these two commands (at least for a while after that date) were different, and the second one is the more "correct" version.
However, although it's correct in LSASrv, it's possible for the ProductVersion and FileVersion to be different (it's common, in fact). So the only way to get the updated Fileversion straight from the assembly file is to build it up yourself from the parts, something like this:
Or by pulling the data from this:
You can easily add this to all FileInfo objects by updating the TypeData in PowerShell:
Now every time you do
Get-ChildItem
orGet-Item
you'll have aFileVersion
property that shows the updated FileVersion ...