Wednesday, May 14, 2014

Get File Version using Powershell


Trying to get the file version of an .EXE file using Powershell, I found the following interesting commands.

This will get the file version of an individual file:

(Get-Command %FILEPATH%).FileVersionInfo

Where %FILEPATH% is the path to a file


(Get-Command “C:\Program Files\Internet Explorer\IExplore.exe”).FileVersionInfo

This will get a list of files in a directory.  (You can also add –recurse to the Get-ChildItem cmdlet to search subdirectories as well)

Get-ChildItem %FILEEXT% | ForEach-Object{Get-Command $_.FullName} | Select –Expand File*

Where %FILEEXT% is the file extension you wish to list.


Get-ChildItem “C:\Program Files\Internet Explorer\*.exe” | ForEach-Object(Get-Command $_.FullName} | Select –Expand File*

Using the first method, if you pipe the results to Get-Member instead of looking at the FileVersionInfo property, you can see there are also a number of other properties available:

CommandType; Definition; Extension; Module; ModuleName; Name; OutputType; Parameters; ParameterSets; Path; RemotingCapability; Visibility; FileVersionInfo; HelpUri


No comments:

Post a Comment