Reputation: 911
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...
Upvotes: 13
Views: 22412
Reputation: 27418
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
Upvotes: 0
Reputation: 1
$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"}
}
enter code here
Upvotes: 0
Reputation: 7153
(Get-ComputerInfo).OsProductType
On my machines this returned either WorkStation
or Server
.
Upvotes: 10
Reputation: 47772
$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
Upvotes: 27