While writing my SQL Server template installer, I ran into a big problem – I had to determine if my server was a Core Edition or not, based on the Windows edition. The biggest challenge was that it had to be as OS-independent as possible. Our customers run several OSs, so I needed something that could run on Windows 2008 R2, Windows 2012 R2 and be future-proof for Windows 2016.
Surfing the interwebs, I found several ways of doing this, but none of them seemed able to work on all the operating systems I wanted to write the template for.
First I tried to use $sku = $((gwmi win32_operatingsystem).OperatingSystemSKU) as described by Jeffrey Snover. But while this approach worked perfectly well for Windows 2008 R2, it didn’t work for Windows 2016.
The default install of Windows 2016 is a core edition, so $sku will return 8 (Datacenter Server Edition) instead of the expected 12 (Datacenter Server Core Edition), even when running the core edition. So that didn’t work out … In fact, the simplest thing to do is to check if the GUI shell is actually installed. But hey, wait a minute. Isn’t that easy if you use Get-WindowsFeature?
You can check all the installed features, can’t you? So by changing the code to: $IsGuiInstalled = $(Get-WindowsFeature -Name “Server-gui-shell” | Select InstallState) I could now verify if $IsGuiInstalled –eq “Available”. If the GUI is still available, you’re running a core edition of Windows. If the state is Installed, you have the GUI ;-)
So my code became:
$IsGuiInstalled = Get-WindowsFeature -Name “Server-gui-shell” | Select InstallState
#Check if we are running on a windows core edition, in that case $IsGuiInstalled should return “Available”
if($IsGuiInstalled -eq “Available”)
{ Write-Verbose “Running on windows GUI” }
else
{ Write-Verbose “Running on windows Core”}