How to check if you’re running on a Windows Core Edition

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” }
{ Write-Verbose “Running on windows Core”}

Group of computer programmers working in the office. Focus is on blond woman showing something to her colleague on PC.
Updating your Azure SQL server OAuth2 credentials in Power BI via PowerShell for automation purposes
The better way to update OAuth2 credentials in Power BI is by automating the process of updating Azure SQL Server...
Under (memory) pressure
A few weeks ago, a client asked me if they were experiencing memory pressure and how they could monitor it...
Managing files from other devices in a Fabric Lakehouse using the Python Azure SDK
In this blogpost, you’ll see how to manage files in OneLake programmatically using the Python Azure SDK. Very little coding...
Database specific security in SQL Server
There are many different ways to secure your database. In this blog post we will give most of them a...
SQL Server security made easy on the server level
In this blog, we’re going to look at the options we have for server level security. In SQL Server we...
Microsoft SQL Server history
Since its inception in 1989, Microsoft SQL Server is a critical component of many organizations' data infrastructure. As data has...