how to get chromedriver.exe version using PowerShell command

Viewed 51

I was writing a PowerShell script to upgrade my webdrivers before starting selenium script, I am able to get the msedgeDriver.exe version using following command but when I use same command for chromedriver.exe it is not returning any output and it does not even through any errors.

This works fine:

(Get-Item C:\xyz\msedgedriver.exe).VersionInfo.FileVersion
  • Output: 104.0.1293.54

Does not return any output:

(Get-Item C:\xyz\chromedriver.exe).VersionInfo.FileVersion
  • Output: Nothing returned

If I try the following it works but why not above one ?

C:\RAV\Web_Drivers\chromedriver.exe --version
  • Output: ChromeDriver 103.0.5060.53 (a1711811edd74ff1cf2150f40b17f-refs/branch-heads/5060@{#763})
1 Answers

As Abraham Zinala commented, the field propably isn't defined for "chromedriver.exe". What you are querying for using VersionInfo.FileVersion is a string field of the version resource, but what you actually should query is the numeric version information. If the string field contains the same value as the numeric version info, then that is just coincidential. It may contain anything or nothing at all. Sometimes the string field isn't regularly updated and may even contain an older version than the numeric fields.

In PowerShell 5.1 and newer, you can query the FileVersionRaw field for the numeric version info:

$version = (Get-Item C:\xyz\msedgedriver.exe).VersionInfo.FileVersionRaw
$version.ToString()  # To format it in the usual dotted format, instead of table format.

In older PowerShell versions, query the individual numeric fields, that make up the version:

$vi = (Get-Item C:\xyz\msedgedriver.exe).VersionInfo
$version = [Version]::new( $vi.FileMajorPart, $vi.FileMinorPart, $vi.FileBuildPart, $vi.FilePrivatePart )
$version.ToString()

If that still doesn't give you anything (which would be very unusual), have a look into the other properties of the VersionInfo, by listing all properties using the Format-List command:

(Get-Item C:\xyz\msedgedriver.exe).VersionInfo | Format-List *
Related