A poor man’s version check for programs on Microsoft Windows using PowerShell

Keeping up to date is a lot of work, especially for programs which do not have an auto-update feature. The first step is to be able to find out what version of a program is actually installed.

PowerShell to the rescue!

For example, to find out what version of InternetExplorer is installed without actually launching it, clicking on the gear and selecting the “Info” option the following PowerShell command can be used:

[System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\Program Files\Internet Explorer\iexplore.exe").Fileversion

The output should look something like this:

$ [System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\Program Files\Internet Explorer\iexplore.exe").Fileversion
9.00.8112.16421 (WIN7_IE9_RTM.110308-0330)

Carveat: Not every program provides the metadata and thus the above can and will fail on some programs…

The PowerShell has a hash table data structure which can be made use of if one wants to check various programs. An example script could look like this:

# clear screen

# set up hash for the programs/paths
$programs = @{}
$programs["Internet Explorer"]     = "C:\Program Files\Internet Explorer\iexplore.exe"
$programs["Notepad"]               = "C:\Windows\system32\notepad.exe" 
$programs["Remote Desktop"]        = "$Env:WinDir\system32\mstsc.exe"
$programs["Windows Media Player"]  = "C:\Program Files (x86)\Windows Media Player\wmplayer.exe" 

# loop the hash and obtain the version for each item in the hash
foreach($key in $programs.keys){
    # prettyprint the output
    "{0,-30}{1,-30}" -f "$key","$version"

Checking for the currently installed Flash version is not quite as easy but can be done like this:

# Check Adobe Flash Version
"Adobe Flash Version Check"
Get-ChildItem -Path C:\Windows -Filter NPSWF32* -Recurse -ErrorAction "SilentlyContinue" | select -expand VersionInfo  |select InternalName,Fileversion

Which, on my machine, shows the following output:

InternalName                                                FileVersion
------------                                                -----------
Adobe Flash Player 11.3                                     11,3,300,268
Adobe Flash Player 11.3                                     11,3,300,268

This is all you need to create a PowerShell script of your own to check specific programs for their versions.
The script can be run like this:

powershell -ExecutionPolicy Unrestricted -File cmv.ps1

For a quick overview you could do the following which creates a CSV (seperatly for each path):

Get-ChildItem -Path "C:\Program Files" -Filter *.exe -Recurse -ErrorAction "SilentlyContinue" | select -expand VersionInfo  | select InternalName,FileDescription,Fileversion  | Export-Csv -Path versions.csv
Get-ChildItem -Path "C:\Program Files (x86)" -Filter *.exe -Recurse -ErrorAction "SilentlyContinue" | select -expand VersionInfo  | select InternalName,FileDescription,Fileversion  | Export-Csv -Path versions-32bit.csv

You could omit the “| Export-Csv” command and substitute the last “select” command for “Format-List” or “Format-Table” if you want to make the output a little prettier. If all you do is to have a text file, I would recommend using Export-Csv.

As you can see, PowerShell is indeed quite powerful but it is very difficult to grasp if you come from a Unix shell background. And it probably would make a lot more sense to implement the above in C# which could also compare the result against a database which contains a list of programs and their current versions… This is left as an exercise for the reader :)