13

This doc explains how to get your windows version, but to find it in PowerShell is harder.

[System.Environment]::OSVersion has a lot of good info but not the Server-Workstation Flag...

0

5 Answers 5

28
$osInfo = Get-CimInstance -ClassName Win32_OperatingSystem $osInfo.ProductType 

See https://msdn.microsoft.com/en-us/library/aa394239%28v=vs.85%29.aspx

ProductType Data type: uint32 Access type: Read-only Additional system information. Work Station (1) Domain Controller (2) Server (3) 

So if the value is 1, then you are on a workstation OS.

If it's 2 you're on a domain controller.

If it's 3 you're on a server that is not a domain controller.


If you're on an old version of Windows / PowerShell and want something that will work across all of them, it's the same, but with Get-WmiObject:

$osInfo = Get-WmiObject -Class Win32_OperatingSystem $osInfo.ProductType 
Sign up to request clarification or add additional context in comments.

5 Comments

Get-CimInstance must be a cmdlet not available on the Win7 version of powershell?
Ok, that's pretty cool. I don't mess with windows much, but do try and work with powershell a bit (a little bit) and do have both older and current powershell (but only the older Win7 virtualized on a network server where I can reach it via rdesktop from Linux). So I learned the Get-CmiInstance -ClassName and Get-WmiObject -Class distiction -- thanks.
@DavidC.Rankin WMI goes back a long time in Windows. An open source version called OMI is also available for other platforms like linux, but CIM is an open standard and so Microsoft recommends the CIM cmdlets going forward, but WMI is alive and well within Windows and will continue to be. PowerShell, starting with the newly released version 6, is open source and cross platform and you can install it on Linux. You might be able to run the CIM cmdlets from *nix against Windows, even older versions. It would be interesting to try.
@DavidC.Rankin The CIM cmdlets were introduced in PowerShell v3, which is also available for Windows 7. The CIM cmdlets do network communication via WinRM, which has a number of advantages over COM/RPC (which the WMI cmdlets are using).
@AnsgarWiechers Hah! -- worked like a champ! We are now both Get-CmiObject and Get-WmiObject capable. Thank you.
10
(Get-ComputerInfo).OsProductType 

On my machines this returned either WorkStation or Server.

6 Comments

Note that Get-ComputerInfo isn't available prior to PowerShell v5.1.
While this is convenient, it comes with two caveats (beyond requiring PSv5.1+): (a) Execution takes on the order of seconds, and even asking only for the property of interest (Get-ComputerInfo -Property OsProductType) doesn't speed things up. (b) A progress bar is invariably shown during execution.
Thank you Kory! I don't feel like upgrading 1000 servers to ps5.1. this will be handy when all the machines are up to date.
Struggling with 1000 servers running Legacy powershell sounds worse than updating them to 5.1 LOL
@PsychoData, well, those 1000 are all in different domains in different locations, at different customer sites ;) if they were all on the same network you could just Chef them or something.
|
0

I've been doing it this way, with 3 example answers:

systeminfo | find "OS Name:" OS Name: Microsoft Windows Server 2016 Standard OS Name: Microsoft Windows 10 Enterprise for Virtual Desktops OS Name: Microsoft Windows 10 Enterprise 

Comments

0
$osType = Try { Get-CIMInstance -Classname Win32_OperatingSystem -ErrorAction Stop | Select -expand ProductType } Catch { Get-WMIObject -Classname Win32_OperatingSystem -ErrorAction Stop | Select -Expand ProductType } Switch ($osType) { 1 {"Workstation"} 2 {"Domain Controller"} 3 {"Member Server"} } 

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
-1

(Get-WmiObject win32_OperatingSystem).Caption

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.