To find the version of Windows that is currently running from the PowerShell command line, you can use the Get-CimInstance
cmdlet and specify the Win32_OperatingSystem
class.
This class contains information about the operating system, including its version, service pack level, and build number.
Here is an example of how to use the Get-CimInstance
cmdlet to get the Windows version:
# Get the operating system information
$os = Get-CimInstance -ClassName Win32_OperatingSystem
# Output the Windows version
Write-Output "The Windows version is: $($os.Version)"
In this example, we use the Get-CimInstance
cmdlet to get information about the operating system, and then use the $os.Version
property to output the Windows version.
The output will be in the format X.Y.Z
, where X
is the version number.
For example, if you are running Windows 10, the output will be 10.0.Z
, where Z
is the build number.
The first two digits of the version number indicate the major version of Windows (e.g. 10
for Windows 10, 16
for Windows Server 2016), and the third digit indicates the minor version or update level (e.g. 0
for the initial release, 1
for the first update, etc.).
You can also use the -ComputerName
parameter of the Get-CimInstance
cmdlet to specify a remote computer, if you want to get the Windows version of a remote machine.
For example:
# Get the operating system information for a remote computer
$os = Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName "RemoteComputerName"
# Output the Windows version
Write-Output "The Windows version on the remote computer is: $($os.Version)"
In this example, we use the -ComputerName
parameter to specify the name of the remote computer, and then use the $os.Version
property to output the Windows version of the remote machine.
The Get-CimInstance
cmdlet is a convenient way to get the Windows version from the PowerShell command line, and can be used to get the version of a local or remote machine.
Related tutorials curated for you
Using -Or in PowerShell
Do Until in PowerShell
What is Echo in PowerShell?
Boolean literals in PowerShell
How to print output in PowerShell
Dictionaries in PowerShell
What is IEX in PowerShell?
What is `ls` for PowerShell?
What is null in PowerShell?
How to select an object in PowerShell
How to use -Contains in PowerShell
How to restart a service in PowerShell