<p>How can you get the version information from a <code>.dll</code> or <code>.exe</code> file in PowerShell?</p>

<p>I am specifically interested in <code>File Version</code>, though other version information (that is, <code>Company</code>, <code>Language</code>, <code>Product Name</code>, etc.) would be helpful as well.</p>

[{'answer_id': 30702, 'author': 'EBGreen', 'author_id': 1358, 'author_profile': 'https://Stackoverflow.com/users/1358', 'pm_score': 3, 'selected': False, 'text': '<pre><code>[System.Diagnostics.FileVersionInfo]::GetVersionInfo("Path\\To\\File.dll")\n</code></pre>\n'}, {'answer_id': 30708, 'author': 'Lars Truijens', 'author_id': 1242, 'author_profile': 'https://Stackoverflow.com/users/1242', 'pm_score': 8, 'selected': True, 'text': '<p>Since PowerShell can call <a href="https://en.wikipedia.org/wiki/.NET_Framework" rel="noreferrer">.NET</a> classes, you could do the following:</p>\n\n<pre><code>[System.Diagnostics.FileVersionInfo]::GetVersionInfo("somefilepath").FileVersion\n</code></pre>\n\n<p>Or as <a href="https://web.archive.org/web/20081004113553/https://kamhungsoh.com/blog/2008/01/powershell-file-version-information.html" rel="noreferrer">noted here</a> on a list of files:</p>\n\n<pre><code>get-childitem * -include *.dll,*.exe | foreach-object { "{0}`t{1}" -f $_.Name, [System.Diagnostics.FileVersionInfo]::GetVersionInfo($_).FileVersion }\n</code></pre>\n\n<p>Or even nicer as a script: <a href="https://jtruher3.wordpress.com/2006/05/14/powershell-and-file-version-information/" rel="noreferrer">https://jtruher3.wordpress.com/2006/05/14/powershell-and-file-version-information/</a></p>\n'}, {'answer_id': 30709, 'author': 'Adam Haile', 'author_id': 194, 'author_profile': 'https://Stackoverflow.com/users/194', 'pm_score': 2, 'selected': False, 'text': '<p>As EBGreen said, [System.Diagnostics.FileVersionInfo]::GetVersionInfo(path) will work, but remember that you can also get all the members of FileVersionInfo, for example:</p>\n\n<pre><code>[System.Diagnostics.FileVersionInfo]::GetVersionInfo(path).CompanyName\n</code></pre>\n\n<p>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.</p>\n'}, {'answer_id': 45718, 'author': 'David Mohundro', 'author_id': 4570, 'author_profile': 'https://Stackoverflow.com/users/4570', 'pm_score': 4, 'selected': False, 'text': '<p>I prefer to install the <a href="https://github.com/Pscx/Pscx" rel="nofollow noreferrer">PowerShell Community Extensions</a> and just use the Get-FileVersionInfo function that it provides.</p>\n<p>Like so:</p>\n<pre>Get-FileVersionInfo MyAssembly.dll</pre>\n<p>with output like:</p>\n<pre>\nProductVersion   FileVersion      FileName\n--------------   -----------      --------\n1.0.2907.18095   1.0.2907.18095   C:\\Path\\To\\MyAssembly.dll\n</pre>\n<p>I\'ve used it against an entire directory of assemblies with great success.</p>\n'}, {'answer_id': 66005, 'author': 'Jaykul', 'author_id': 8718, 'author_profile': 'https://Stackoverflow.com/users/8718', 'pm_score': 8, 'selected': False, 'text': '<p>Since PowerShell 5 in Windows 10, you can look at <code>FileVersionRaw</code> (or ProductVersionRaw) on the output of <code>Get-Item</code> or <code>Get-ChildItem</code>, like this:</p>\n<pre><code>(Get-Item C:\\Windows\\System32\\Lsasrv.dll).VersionInfo.FileVersionRaw\n</code></pre>\n<p>It\'s actually the same <code>ScriptProperty</code> from my <code>Update-TypeData</code> in the original answer below, but built-in now.</p>\n<p>In PowerShell 4, you could get the FileVersionInfo from Get-Item or Get-ChildItem, but it would show the original FileVersion from the shipped product, and not the updated version. For instance:</p>\n<pre><code>(Get-Item C:\\Windows\\System32\\Lsasrv.dll).VersionInfo.FileVersion\n</code></pre>\n<p>Interestingly, you could get the updated (patched) <em>ProductVersion</em> by using this:</p>\n<pre><code>(Get-Command C:\\Windows\\System32\\Lsasrv.dll).Version\n</code></pre>\n<p>The distinction I\'m making between &quot;original&quot; and &quot;patched&quot; is basically due to the way the FileVersion is calculated (<a href="https://learn.microsoft.com/en-us/windows/win32/api/winver/nf-winver-getfileversioninfoa#remarks" rel="noreferrer">see the docs here</a>). 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).</p>\n<p>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 <strong>second one</strong> is the more &quot;correct&quot; version.</p>\n<p>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 <em>updated</em> Fileversion straight from the assembly file is to build it up yourself from the parts, something like this:</p>\n<pre><code>Get-Item C:\\Windows\\System32\\Lsasrv.dll | ft FileName, File*Part\n</code></pre>\n<p>Or by pulling the data from this:</p>\n<pre><code>[System.Diagnostics.FileVersionInfo]::GetVersionInfo($this.FullName)\n</code></pre>\n<p>You can easily add this to all FileInfo objects by updating the TypeData in PowerShell:</p>\n<pre><code>Update-TypeData -TypeName System.IO.FileInfo -MemberName FileVersionRaw -MemberType ScriptProperty -Value {\n   [System.Diagnostics.FileVersionInfo]::GetVersionInfo($this.FullName) | % {\n      [Version](($_.FileMajorPart, $_.FileMinorPart, $_.FileBuildPart, $_.FilePrivatePart)-join&quot;.&quot;) \n   }\n}\n</code></pre>\n<p>Now every time you do <code>Get-ChildItem</code> or <code>Get-Item</code> you\'ll have a <code>FileVersionRaw</code> property that shows the updated File Version ...</p>\n'}, {'answer_id': 2159806, 'author': 'xcud', 'author_id': 61396, 'author_profile': 'https://Stackoverflow.com/users/61396', 'pm_score': 6, 'selected': False, 'text': "<p>'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 ... </p>\n\n<p>To get the version info of a single file do this:</p>\n\n<pre><code>PS C:\\Windows&gt; (dir .\\write.exe).VersionInfo | fl\n\n\nOriginalFilename : write\nFileDescription  : Windows Write\nProductName      : Microsoft® Windows® Operating System\nComments         :\nCompanyName      : Microsoft Corporation\nFileName         : C:\\Windows\\write.exe\nFileVersion      : 6.1.7600.16385 (win7_rtm.090713-1255)\nProductVersion   : 6.1.7600.16385\nIsDebug          : False\nIsPatched        : False\nIsPreRelease     : False\nIsPrivateBuild   : False\nIsSpecialBuild   : False\nLanguage         : English (United States)\nLegalCopyright   : © Microsoft Corporation. All rights reserved.\nLegalTrademarks  :\nPrivateBuild     :\nSpecialBuild     :\n</code></pre>\n\n<p>For multiple files this:</p>\n\n<pre><code>PS C:\\Windows&gt; dir *.exe | %{ $_.VersionInfo }\n\nProductVersion   FileVersion      FileName\n--------------   -----------      --------\n6.1.7600.16385   6.1.7600.1638... C:\\Windows\\bfsvc.exe\n6.1.7600.16385   6.1.7600.1638... C:\\Windows\\explorer.exe\n6.1.7600.16385   6.1.7600.1638... C:\\Windows\\fveupdate.exe\n6.1.7600.16385   6.1.7600.1638... C:\\Windows\\HelpPane.exe\n6.1.7600.16385   6.1.7600.1638... C:\\Windows\\hh.exe\n6.1.7600.16385   6.1.7600.1638... C:\\Windows\\notepad.exe\n6.1.7600.16385   6.1.7600.1638... C:\\Windows\\regedit.exe\n6.1.7600.16385   6.1.7600.1638... C:\\Windows\\splwow64.exe\n1,7,0,0          1,7,0,0          C:\\Windows\\twunk_16.exe\n1,7,1,0          1,7,1,0          C:\\Windows\\twunk_32.exe\n6.1.7600.16385   6.1.7600.1638... C:\\Windows\\winhlp32.exe\n6.1.7600.16385   6.1.7600.1638... C:\\Windows\\write.exe\n</code></pre>\n"}, {'answer_id': 6959632, 'author': 'Wes', 'author_id': 880959, 'author_profile': 'https://Stackoverflow.com/users/880959', 'pm_score': 4, 'selected': False, 'text': '<p>Just another way to do it is to use the built-in file access technique:</p>\n\n<pre><code>(get-item .\\filename.exe).VersionInfo | FL\n</code></pre>\n\n<p>You can also get any particular property off the VersionInfo, thus:</p>\n\n<pre><code>(get-item .\\filename.exe).VersionInfo.FileVersion\n</code></pre>\n\n<p>This is quite close to the dir technique.</p>\n'}, {'answer_id': 11740080, 'author': 'Chriseyre2000', 'author_id': 662571, 'author_profile': 'https://Stackoverflow.com/users/662571', 'pm_score': 2, 'selected': False, 'text': '<p>I find this useful:</p>\n\n<pre><code>function Get-Version($filePath)\n{\n   $name = @{Name="Name";Expression= {split-path -leaf $_.FileName}}\n   $path = @{Name="Path";Expression= {split-path $_.FileName}}\n   dir -recurse -path $filePath | % { if ($_.Name -match "(.*dll|.*exe)$") {$_.VersionInfo}} | select FileVersion, $name, $path\n}\n</code></pre>\n'}, {'answer_id': 20265055, 'author': 'noelicus', 'author_id': 865643, 'author_profile': 'https://Stackoverflow.com/users/865643', 'pm_score': 3, 'selected': False, 'text': '<p>This is <em>based</em> on the other answers, but is exactly what I was after:  </p>\n\n<pre><code>(Get-Command C:\\Path\\YourFile.Dll).FileVersionInfo.FileVersion\n</code></pre>\n'}, {'answer_id': 25166557, 'author': 'Knuckle-Dragger', 'author_id': 3093031, 'author_profile': 'https://Stackoverflow.com/users/3093031', 'pm_score': 1, 'selected': False, 'text': '<p>Here an alternative method.  It uses Get-WmiObject CIM_DATAFILE to select the version.</p>\n\n<pre><code>(Get-WmiObject -Class CIM_DataFile -Filter "Name=\'C:\\\\Windows\\\\explorer.exe\'" | Select-Object Version).Version\n</code></pre>\n'}, {'answer_id': 50967364, 'author': 'm-smith', 'author_id': 515857, 'author_profile': 'https://Stackoverflow.com/users/515857', 'pm_score': 4, 'selected': False, 'text': '<p>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+:</p>\n\n<pre><code>ls application.exe | % versioninfo\n</code></pre>\n\n<ul>\n<li><code>ls</code> is an alias for <code>Get-ChildItem</code></li>\n<li><code>%</code> is an alias for <code>ForEach-Object</code></li>\n<li><code>versioninfo</code> here is a shorthand way of writing <code>{$_.VersionInfo}</code></li>\n</ul>\n\n<p>The benefit of using <code>ls</code> 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 called <code>application.exe</code> within subfolders:</p>\n\n<pre><code>ls application.exe -r | % versioninfo\n</code></pre>\n\n<ul>\n<li><code>-r</code> is an alias for <code>-Recurse</code></li>\n</ul>\n\n<p>You can further refine this by adding <code>-ea silentlycontinue</code> to ignore things like permission errors in folders you can\'t search:</p>\n\n<pre><code>ls application.exe -r -ea silentlycontinue | % versioninfo\n</code></pre>\n\n<ul>\n<li><code>-ea</code> is an alias for <code>-ErrorAction</code></li>\n</ul>\n\n<p>Finally, if you are getting ellipses (...) in your results, you can append <code>| fl</code> 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:</p>\n\n<pre><code>ls application.exe -r -ea silentlycontinue | % versioninfo | fl\n</code></pre>\n\n<ul>\n<li><code>fl</code> is an alias for <code>Format-List</code></li>\n</ul>\n\n<p>I realise this is very similar to xcud\'s reply in that <code>ls</code> and <code>dir</code> are both aliases for <code>Get-ChildItem</code>. But I\'m hoping my "shortest" method will help someone.</p>\n\n<p>The final example could be written in long-hand in the following way:</p>\n\n<pre><code>Get-ChildItem -Filter application.exe -Recurse -ErrorAction SilentlyContinue | ForEach-Object {$_.VersionInfo} | Format-List\n</code></pre>\n\n<p>... but I think my way is cooler and, for some, easier to remember. (But mostly cooler).</p>\n'}]
['https://Stackoverflow.com/questions/30686', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2495/']