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...
To find the service name and display name of each service on your system, type Get-Service . The service names appear in the Name column, and the display names appear in the DisplayName column. When you sort in ascending order by status value, Stopped services appear before Running services.
Enter the PowerShell system info commandType Get-ComputerInfo and press “Enter”. It will return all of your system specifications, from the Windows version to Bios data.
$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
(Get-ComputerInfo).OsProductType
On my machines this returned either WorkStation
or Server
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With