As a system administrator or developer, I often need to know the specific version of Windows running on a machine. In this tutorial, I will explain how to get the Windows version using PowerShell using different methods.
Get the Windows Version Using PowerShell
Now, let me show you different methods to get the Windows version using PowerShell.
Method 1: Using the [Environment]::OSVersion Property
One of the simplest ways to retrieve the Windows version using PowerShell is by accessing the [Environment]::OSVersion property. Here’s an example:
$windowsVersion = [Environment]::OSVersion
Write-Host "Windows Version: $($windowsVersion.Version)"In this code snippet, we assign the [Environment]::OSVersion property to the $windowsVersion variable. We then use Write-Host to display the version information by accessing the Version property of $windowsVersion.
I executed the above PowerShell script and you can see it displays me the current Windows version that I am using.

For instance, let’s say you’re a system administrator at a company in New York, and you need to check the Windows version of a server named “NYServer01”. You can use the following script:
$serverName = "NYServer01"
$windowsVersion = Invoke-Command -ComputerName $serverName -ScriptBlock { [Environment]::OSVersion }
Write-Host "Windows Version on $serverName : $($windowsVersion.Version)" This script uses the Invoke-Command cmdlet to execute the command remotely on the specified server and retrieve the Windows version information.
If you want to get Windows Version and Build using PowerShell, then you can use the [System.Environment]::OSVersion property. This property provides the version number in a more granular format.
[System.Environment]::OSVersion.VersionThis command will output something like:
Major Minor Build Revision
----- ----- ----- --------
10 0 22631 0I executed the above PowerShell cmdlet, and you can see the exact output in the screenshot below:

Check out Get HP Laptop Model and Serial Number Using PowerShell
Method 2: Using the Registry
Another approach to get the Windows version is by querying the registry. PowerShell allows you to access registry values easily. Here’s an example:
$registryKey = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
$windowsVersion = (Get-ItemProperty -Path $registryKey -Name ReleaseID).ReleaseID
Write-Host "Windows Version: $windowsVersion"In this code, we specify the registry key path that contains the Windows version information. We then use the Get-ItemProperty cmdlet to retrieve the value of the ReleaseID registry entry and store it in the $windowsVersion variable.
For example, let’s say you’re an IT consultant based in California, and a client asks you to check the Windows version of their workstation named “LAWorkstation”. You can use the following script:
$computerName = "LAWorkstation"
$registryKey = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
$windowsVersion = Invoke-Command -ComputerName $computerName -ScriptBlock {
(Get-ItemProperty -Path $registryKey -Name ReleaseID).ReleaseID
}
Write-Host "Windows Version on $computerName : $windowsVersion"This script uses Invoke-Command to execute the registry query remotely on the specified workstation and retrieve the Windows version.
Check out How to Use PowerShell Read-Host?
Method 3: Using the Get-ComputerInfo Cmdlet
Starting from Windows PowerShell 5.1, you can use the Get-ComputerInfo cmdlet to retrieve detailed information about a computer, including the Windows version. Here’s an example:
$computerInfo = Get-ComputerInfo
Write-Host "Windows Version: $($computerInfo.OsVersion)"
Write-Host "Windows Edition: $($computerInfo.OsName)"In this code, we use the Get-ComputerInfo cmdlet to retrieve computer information and store it in the $computerInfo variable. We then access the OsVersion and OsName properties to display the Windows version and edition, respectively.
For instance, let’s say you’re a IT support specialist in Texas, and you need to check the Windows version and edition of a user’s laptop named “DallasLaptop”. You can use the following script:
$laptopName = "DallasLaptop"
$computerInfo = Invoke-Command -ComputerName $laptopName -ScriptBlock { Get-ComputerInfo }
Write-Host "Windows Version on $laptopName : $($computerInfo.OsVersion)"
Write-Host "Windows Edition on $laptopName : $($computerInfo.OsName)" This script uses Invoke-Command to execute Get-ComputerInfo remotely on the specified laptop and retrieve the Windows version and edition information.
Check out How to Use PowerShell Get-Process?
Method 4: Using WMI (Windows Management Instrumentation)
WMI is a powerful tool for retrieving system information, including the Windows version. Here’s an example of how to use WMI with PowerShell:
$wmiQuery = "SELECT * FROM Win32_OperatingSystem"
$operatingSystem = Get-WmiObject -Query $wmiQuery
Write-Host "Windows Version: $($operatingSystem.Version)"In this code, we define a WMI query to select all properties from the Win32_OperatingSystem class. We then use the Get-WmiObject cmdlet to execute the query and store the result in the $operatingSystem variable. Finally, we access the Version property to display the Windows version.
I executed the above PowerShell script; it displays me the exact information like in the screenshot below;

For example, let’s say you’re a system administrator in Florida, and you need to check the Windows version of a server named “MiamiServer”. You can use the following script:
$serverName = "MiamiServer"
$wmiQuery = "SELECT * FROM Win32_OperatingSystem"
$operatingSystem = Invoke-Command -ComputerName $serverName -ScriptBlock {
Get-WmiObject -Query $wmiQuery
}
Write-Host "Windows Version on $serverName : $($operatingSystem.Version)"This script uses Invoke-Command to execute the WMI query remotely on the specified server and retrieve the Windows version information.
Conclusion
In this tutorial, I explained various methods to retrieve the Windows version using PowerShell. You can use various methods such as using the [Environment]::OSVersion property, querying the registry, utilizing the Get-ComputerInfo cmdlet, or leveraging WMI, etc.
I am sure this tutorial will help you as a PowerShell administrator.
You may also like:
- PowerShell Compare-Object
- How to List Local Administrators Using PowerShell?
- How to Get Window Titles Using PowerShell?
- Rename a Computer Using PowerShell
- How to Retrieve Your Windows Product Key Using PowerShell?
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.