Printing various file version properties with PowerShell

Some files have version numbers. Some don’t. Some have more than one version number. Sometimes the version number is also a string. Sometimes the string matches the version number. Sometimes it doesn’t.

.NET comes with a System.Diagnostics.FileVersionInfo object that allows you to read all of these. I wrote up a quick fileversioninfo.ps1 PowerShell script to dump the object, given a filename. Let’s see what it shows:

>.\FileVersionInfo.ps1 -filename ${env:windir}\system32\ntdll.dll
-- File names and descriptions --
FileName: C:\WINDOWS\system32\ntdll.dll
InternalName: ntdll.dll
OriginalFilename: ntdll.dll.mui
FileDescription: NT Layer DLL
Comments: 

-- File version --
FileVersion: 10.0.21263.1000 (WinBuild.160101.0800)
File(Major.Minor.Build.Private)Part: 10.0.21263.1000

-- Product info --
ProductName: Microsoft® Windows® Operating System
ProductVersion: 10.0.21263.1000
Product(Major.Minor.Build.Private)Part: 10.0.21263.1000

-- Legal info --
Company Name: Microsoft Corporation
LegalCopyright: © Microsoft Corporation. All rights reserved.
LegalTrademarks:

-- Private build info --
IsPrivateBuild: False
PrivateBuild:

-- Special build info --
IsSpecialBuild: False
SpecialBuild:

-- Other info --
Language: English (United States)
IsDebug: False
IsPatched: False
IsPreRelease: False

Note that FileVersion is a string, while FileMajorPart, FileMinorPart, FileBuildPart, and FilePrivatePart are all numbers. If you make a file and you include file version information, make sure your FileVersion is consistent with your (FileMajorPart, FileMinorPart, FileBuildPart, FilePrivatePart).

Also note that ProductVersion is a string, while ProductMajorPart, ProductMinorPart, ProductBuildPart, and ProductPrivatePart are all numbers. If you make a file and you include product version information, make sure your ProductVersion is consistent with your (ProductMajorPart, ProductMinorPart, ProductBuildPart, ProductPrivatePart).

In the example case I showed, the file version is self-consistent; the product version is self-consistent; and the file version and product version are the same as each other. But this need not be the case. It’s fine for the file version and the product version to be different. But the both of them should be self-consistent.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s