Get File Version in PowerShell

Rohan Timalsina Jan 30, 2023 Feb 23, 2022
  1. Use Get-Item to Get File Version in PowerShell
  2. Use Get-ChildItem to Get File Version in PowerShell
  3. Use Get-Command to Get File Version in PowerShell
  4. Use System.Diagnostics.FileVersionInfo to Get File Version in PowerShell
Get File Version in PowerShell

A file version number is a 64-bit number representing the version number for a file.

The executable files contain version information, such as .exe and .dll. Text files do not have any version information.

The version information holds the file name, file version, company name, product name, product version, and language. This tutorial will teach you to get the file version in PowerShell.

Use Get-Item to Get File Version in PowerShell

The Get-Item cmdlet gets the item at the specified location. You can use the VersionInfo.FileVersion property to get the file version number in PowerShell.

The following example shows how to use Get-Item and VersionInfo.FileVersion to get the version of a file C:\Program Files\Google\Chrome\Application\chrome.exe.

(Get-Item "C:\Program Files\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion

A version number is displayed as major number.minor number.build number.private part number.

Output:

98.0.4758.102

Use Get-ChildItem to Get File Version in PowerShell

The Get-ChildItem gets the items and child items in one or more specified locations. You can also use Get-ChildItem with the VersionInfo.FileVersion property to get the file version in PowerShell.

(Get-ChildItem "C:\Program Files\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion

Output:

98.0.4758.102

Use Get-Command to Get File Version in PowerShell

The Get-Command cmdlet gets all commands installed on the computer. It includes all cmdlets, aliases, functions, scripts, and applications.

You can use the FileVersionInfo.FileVersion property with the Get-Command to get the file version in PowerShell.

The following command gets the file version number of a file C:\Windows\System32\ActionCenter.dll.

(Get-Command C:\Windows\System32\ActionCenter.dll).FileVersionInfo.FileVersion

Output:

10.0.19041.1 (WinBuild.160101.0800)

Use System.Diagnostics.FileVersionInfo to Get File Version in PowerShell

The System.Diagnostics.FileVersionInfo class from the .NET Framework provides version information of a file.

You can use the GetVersionInfo() method and the FileVersion property to get the file version number.

[System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\Windows\System32\ActionCenter.dll").FileVersion

Output:

10.0.19041.1 (WinBuild.160101.0800)

We hope this tutorial gave you an idea of getting the file version in PowerShell.

Rohan Timalsina avatar Rohan Timalsina avatar

Rohan is a learner, problem solver, and web developer. He loves to write and share his understanding.

LinkedIn Website

Related Article - PowerShell File