Identifying Your Windows Version with PowerShell
PowerShell is a powerful command-line shell and scripting language available on Windows systems. A common task for system administrators and developers is to determine the version of Windows a system is running. This tutorial will guide you through several methods of achieving this using PowerShell.
Using the .NET Framework
The .NET Framework provides access to operating system information through the System.Environment
class. The OSVersion
property contains detailed information about the Windows version. Specifically, the Version
property gives you the major, minor, build, and revision numbers.
[System.Environment]::OSVersion.Version
This will output a series of numbers representing the Windows version. For example:
Major Minor Build Revision
----- ----- ----- --------
6 1 7601 65536
This indicates Windows 7. You can interpret these numbers to determine the specific Windows release.
Leveraging WMI (Windows Management Instrumentation)
WMI is a core component of Windows that provides a standardized way to manage and retrieve information about the system. You can use PowerShell to query WMI classes to get the Windows version.
(Get-WmiObject -class Win32_OperatingSystem).Caption
This command retrieves the Caption
property from the Win32_OperatingSystem
class, which provides a human-readable string describing the operating system. For example:
Microsoft Windows 10 Pro
Note: For newer versions of PowerShell based on cross-platform .NET (pwsh), use Get-CimInstance
instead of Get-WmiObject
:
(Get-CimInstance Win32_OperatingSystem).Caption
Determining Windows 10 Specific Versions
Windows 10 introduces a more granular versioning system beyond the standard major and minor numbers. Each major feature update receives a unique identifier.
To retrieve this identifier, you can access the ReleaseId
value from the registry:
(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId
This will output a string like 10.0.19041.1706
which identifies a specific Windows 10 build. You can also query the registry using cmd
:
Reg Query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ReleaseId
Using Get-ComputerInfo
PowerShell provides the Get-ComputerInfo
cmdlet which consolidates a wealth of system information, including the Windows version.
Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer
This will output information similar to:
WindowsProductName WindowsVersion OsHardwareAbstractionLayer
------------------ -------------- --------------------------
Windows 10 Enterprise 1709 10.0.16299.371
Accessing File Version Information
For the most detailed versioning, including the build number, you can query the version information of a system file, such as hal.dll
.
(Get-ItemProperty -Path "C:\windows\system32\hal.dll").VersionInfo.FileVersion
This often returns a string that looks like:
10.0.10240.16392 (th1_st1.150716-1608)
This provides the most comprehensive version identifier, including the build and a codename for the release.
Choosing the Right Method
The best method to use depends on the level of detail you require:
- For a quick, human-readable name:
(Get-WmiObject -class Win32_OperatingSystem).Caption
- For major/minor/build/revision numbers:
[System.Environment]::OSVersion.Version
- For Windows 10 specific Release IDs:
(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId
- For the most detailed version information:
(Get-ItemProperty -Path "C:\windows\system32\hal.dll").VersionInfo.FileVersion
- For a consolidated view of multiple properties:
Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer