Published on

June 29, 2015

Understanding SQL Server Licensing with PowerShell

Working with PowerShell scripts can be an interesting journey, especially when combining the use of Windows Management Instrumentation (WMI) with PowerShell. In this blog post, we will explore how to find the number of logical processors (cores) on a SQL Server machine using PowerShell.

When SQL Server changed its licensing process from processor-based licensing to core-based licensing, many of us were left confused about how to calculate the number of logical processors. Recently, a DBA friend of mine asked me how to find this information. After searching extensively, I realized there wasn’t much available on this topic. So, I decided to write a simple script that I could refer to in the future.

Let’s take a look at the PowerShell script:

$Computer = 'localhost'
$ErrorActionPreference = 'SilentlyContinue'
$Error.Clear()
$ProcessorConfig = Get-WmiObject -class Win32_Processor -computername $Computer -namespace root\CIMV2 | Select PSComputerName, Name, NumberOfCores, NumberOfLogicalProcessors

If ($Error.Count -gt 0)
{
    $ProcessorConfig = New-Object psobject
    $ProcessorConfig | Add-Member -type NoteProperty -name ComputerName ("$Computer - failed to connect")
    $ProcessorConfig | Add-Member -type NoteProperty -name Name -value 'Unable to get ProcessorInfo'
    $ProcessorConfig | Add-Member -type NoteProperty -name NumberOfCores -value $null
    $ProcessorConfig | Add-Member -type NoteProperty -name NumberOfLogicalProcessors -value $null
}

$ErrorActionPreference = 'Continue'
$ProcessorConfig | FT * -AutoSize

When you run this script in PowerShell, you will see an output similar to the following:

PSComputerName : localhost
Name           : Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
NumberOfCores  : 6
NumberOfLogicalProcessors : 12

In the above example, we can see that the machine has a 6-core processor with Hyper-Threading (HT) enabled, resulting in a total of 12 logical processors.

Using PowerShell and WMI to retrieve this information is a quick and efficient way to understand the hardware configuration of your SQL Server machine. It can be particularly useful when dealing with licensing calculations or troubleshooting performance issues.

If you have used WMI or PowerShell to solve interesting problems, I would love to hear about your experiences. Please share your thoughts and insights in the comments section below. I will try to publish more articles based on your inputs in the future.

Click to rate this post!
[Total: 0 Average: 0]

Let's work together

Send us a message or book free introductory meeting with us using button below.