Search code examples
powershellpowershell-2.0

How do I find out from powershell if I am on a server or workstation?


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...


Solution

  • $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