Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to detect if a 2012 server is has been setup as a Core install using WMI. An earlier question, would seem to indicate that I can get the OperatingSystemSKU from Win32_OperatingSystem. My Windows 2012 Core systems are reporting a OperatingSystemSKU of 7. The article from the other question would seem to indicate is a PRODUCT_STANDARD_SERVER, and if had a core install I should expect to see a value of 0x0000000D instead for PRODUCT_STANDARD_SERVER_CORE.

What am I missing here. I eventually want to create a policy and use item level targeting to only apply that policy to Windows 2012 Server Core installs.

PS C:\Users\zoredache\Documents> gwmi -Query "select OPeratingSystemSKU,Version,ProductType from Win32_OperatingSystem"

__GENUS            : 2
__CLASS            : Win32_OperatingSystem
__SUPERCLASS       :
__DYNASTY          :
__RELPATH          : Win32_OperatingSystem=@
__PROPERTY_COUNT   : 3
__DERIVATION       : {}
__SERVER           :
__NAMESPACE        :
__PATH             :
OperatingSystemSKU : 7
ProductType        : 2
Version            : 6.2.9200
share|improve this question
    
As a slight deflection to your question... How would one define server core? I read that server core is just the same with one or two less features installed (the GUI). Could you not query for that instead? –  john Aug 6 '13 at 19:30
    
If you can provide an answer on how to detect that feature is installed via WMI, then I would upvote it, and test it out. Any answer that can be used to identify Server core with WMI would be helpful in my opinion. –  Zoredache Aug 6 '13 at 19:33
    
Try using WMI on the remote machines. Get-WMIObject Win32_OptionalFeature | Select Name, InstallState and filter on whether the server has the server GUI bits installed or not. –  Ryan Ries Aug 6 '13 at 19:33
add comment

4 Answers

up vote 14 down vote accepted

In PowerShell:

Get-WMIObject Win32_OptionalFeature | where Name -eq 'Server-Gui-Shell' | Select InstallState

returns 1 on a full server and 2 on a server core install.

Edit:

While my answer above is correct, there are two problems with it:

  1. When using this command on a workstation, it returns nothing, so you have to add an extra check for this.

  2. It is slow, when I tried it, it took between 600 and 3500 milliseconds.

So the more pragmatic approach is to just check for the existence of a certain file:

(Test-Path "$env:windir\explorer.exe")

This returns $false for a Server Core installations and $true for all others and it takes one millisecond to execute.

share|improve this answer
add comment

As the GUI is just a feature, you can query the list of installed features

Just testing this in powershell on a server here worked well enough:

Dump a list of features to grab the name

Get-WmiObject Win32_OptionalFeature > features.txt

Searching the text of features.txt tells me that the feature is named 'Server-Gui-Mgmt' (other features may be installed too as Michael notes in his answer, so you can test for those too), and we can search to see if that's present

Get-WmiObject -query "select * from Win32_OptionalFeature where name = 'Server-Gui'"

enter image description here

share|improve this answer
add comment

Funny, that MSDN article you linked contained the answer:

PRODUCT_*_SERVER_CORE values are not returned in Windows Server 2012.

This is because Server 2012 can be freely converted between "Server Core" and "full" installation simply by adding or removing the appropriate features.

You will want to check for the presence or absence of those features (e.g. Server-Gui-Mgmt-Infra, Server-Gui-Shell, Desktop-Experience).

share|improve this answer
add comment

I suspect that since they are essentially the same in 2012 with just a few optional features to set them apart, you could query the features instead.

this article is a reference for the Win32_OptionalFeature class, which will allow you to query the features. The optional features are defined as Server-Gui-Mgmt-Infra, Server-Gui-Shell and Desktop-Experience, as outlined in this article.

You can query for the 3 of them and use Boolean AND and NOT logic to select servers which have none of these features installed.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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