Home » PowerShell Tips » Get File Version in PowerShell

Get File Version in PowerShell

The command to get the file version in PowerShell is the Get-Command cmdlet. This command uses FileVersionInfo.FileVersion property to get the version of the file.

File version and naming are very important in the file system directory. File version information contains the version number of the file and the original file name. You can use PowerShell to get file version using Get-Command, Get-Item cmdlet.

In this article, we will discuss how to get file version in PowerShell using Get-Command and other PowerShell cmdlets.

Let’s understand how to get file version and get dll assembly file version with examples.

Get File Version in PowerShell using Get-Command

You can get file version of the file using the PowerShell Get-Command cmdlet.

Let’s consider an example if we want to get dll assembly file version, use the below command

(Get-Command D:\PowerShell\ShellWatcher.dll).FileVersionInfo.FileVersion

In the above command, Get-Command gets dll assembly file version of the specified file using FileVersionInfo.FileVersion property.

FileVersionInfo.FileVersion property get file version number as “major number.minor number.build number.private part number”

The output of the above command to get file version in PowerShell as below

Get dll assembly file version in PowerShell
Get dll assembly file version in PowerShell

Cool Tip: How to find file by name in PowerShell!

Get Exe File version PowerShell

You can get exe file version in PowerShell using Get-Command as below

 (Get-Command D:\PowerShell\ShellIndex.exe).FileVersionInfo.FileVersion    

In the above command, FileVersionInfo.FileVersion property get exe file version as below for specified file

PS C:\> (Get-Command D:\PowerShell\ShellIndex.exe).FileVersionInfo.FileVersion                   2.0.3.0
PS C:\>   

Cool Tip: How to rename a computer in PowerShell!

Get dll assembly file version using Get-Item

In PowerShell, you can get dll assembly file version using Get-Item cmdlet as below

(Get-Item D:\PowerShell\ShellWatcher.dll).VersionInfo | format-list  

PowerShell Get-Item cmdlet gets the item at the specified location and using VersionInfo property, it get file version in PowerShell as below

PS C:\> (Get-Item D:\PowerShell\ShellWatcher.dll).VersionInfo | format-list                                             

FileName          : D:\PowerShell\ShellWatcher.dll
FileVersion       : 19.10.20064.310990
ProductVersion    : 19.10.20064.310990

Cool Tip: How to add content to file in PowerShell!

Conclusion

I hope the above article on how to get file version in PowerShell and get dll assembly file version using the Get-Command cmdlet is helpful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.