Saturday, April 4, 2020

PowerShell: Getting Chrome's Version Number

As part of some DevOps work I have been performing automations using Selenium driven by PowerShell (more on that later). In order to automate a browser such as Chrome is it is handy to know what version Chrome is installed on a give machine.

The code required is fairly straight forward as shown by ChromeSupport.psm1:

class ChromeSupport {
    hidden static [string] $Key =
        'HKLM:\SOFTWARE\Microsoft\Windows\' +
        'CurrentVersion\App Paths\chrome.exe'


    static [System.Diagnostics.FileVersionInfo] GetVersionInfo() {
        [string] $path = 

          (Get-ItemProperty ([ChromeSupport]::Key)).'(Default)'

        return (Get-Item $path).VersionInfo
    }

}


The moduel is invoked from Powershell script, AutomationDriver.ps1:

using module '.\ChromeSupport.psm1'

[ChromeSupport]::GetVersionInfo()

The output from the above script is as follows:


Getting the product version is as matter of invoking the code as follows:

using module '.\ChromeSupport.psm1'

[ChromeSupport]::GetVersionInfo().ProductVersion

The previous code displays:





No comments :

Post a Comment