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
In PowerShell:
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:
When using this command on a workstation, it returns nothing, so you have to add an extra check for this.
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:
This returns
$false
for a Server Core installations and$true
for all others and it takes one millisecond to execute.Funny, that MSDN article you linked contained the answer:
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).
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
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
I would use Win32_ServerFeature, it is a much smaller class and only contains the roles installed on the server. Queries using Win32_Server feature should return much quicker.
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.
Some clarification on the answers for local and remote scenarios as performance was discussed. The questioner asked WMI, and his example used PowerShell to invoke WMI. Using WMI directly from unmanaged code is also quicker.
Please note that the approaches apply effectively to Server 2012 and Server 2012 R2, and may not apply to future releases.
Some trade offs depending on your scenario... For most cases, Win32_ServerFeature is preferred as a general solution, or the local file check in a pinch.
That covers online local and remote scenarios. Some of the above also will target an offline image.
I just thought I'd chime in with a WMI Filter for this solution, so you can apply GPOs to Core 2012+ systems:
To test this on the command line:
I stumbled on this thread when trying to find a way to create WMI Filters for Core 2012 servers, and for some reason it didn't occur to me to have WMI check Win32_OptionalFeature (or indeed, that such a path exists). Hope this helps someone else.
On Windows Server 2012 R2, I'm using the following, performance is good while still being quite explicit.