2

I would like to check which version of windows is used in a remote machine, I'm using this command:

$version=[Environment]::OSVersion.Version | % {"{0}.{1}.{2}" -f $_.Major,$_.Minor,$_.Build}

I get the result for example windows 7 : 6.1.7600

but I found a problem :

Windows server 2012 R2 have : 6.1.9600

and windows 8.1 too : 6.1.9600

so I'm wondering if there is an other solution to get the version of windows?

6

Another solution would be to get the caption via CIM. I think it's closest to what you want. It can be used to check local and Remote machines.


Local:

Get-CimInstance Win32_Operatingsystem | Select-Object -expand Caption

Example Output:

PS C:\WINDOWS\system32> Get-CimInstance Win32_Operatingsystem | select -expand Caption
Microsoft Windows 10 Pro

Remote:

Add the -computername parameter to Get-CimInstance

Example Output:

PS C:\WINDOWS\system32> Get-CimInstance Win32_Operatingsystem -ComputerName xy | select -expand Caption
Microsoft Windows 7 Professional

Run Get-CimInstance Win32_Operatingsystem | fl * to see which properties you can additionally select to get the output you want.

  • thanks you very much sir!it's very useful.. i really appreciate your help – Hkm Mahjoub Jun 2 '16 at 18:27
  • This method was deprecated with Windows 8.1. See this link for details. – Slogmeister Extraordinaire Aug 8 '17 at 15:10
  • Edited and changed Get-WmiObject to Get-CimInstance – SimonS Feb 15 '19 at 14:15
1

I'm wondering if there is an other solution to get the version of windows?

Use the following command to retrieve the full Version String (which includes the Name, Version, and Service Pack number:

[Environment]::OSVersion.VersionString

Example output:

PS F:\test> [Environment]::OSVersion.VersionString
Microsoft Windows NT 6.1.7601 Service Pack 1
PS F:\test> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.