Get File Version in PowerShell

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

In this article, I will explain 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 file using 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 get 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 an above command to get file version in PowerShell as below

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 Get-Command cmdlet is helpful to you.

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

Leave a Comment