PowerShell Tip of the Week: SQL Server Native Client version

Recently I had to extract SQL Server Native Client version from all of my SQL machines. I would like to share simple script for extracting that information remotely from registry.

SQL Server Native Client

To find version using PowerShell we need to know where is it located. Easiest way for me was extracting this from registry:

SQL Server 2008/2008 R2:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SQLNCLI10\CurrentVersion

SQL Server 2012/2016:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SQLNCLI11\CurrentVersion

You can also check it using PowerShell:

#Locally
{(Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\").name}

#On remote machine
Icm -cn SQLServer01 {(Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\").name}

Now, when we know what is the registry path we can use Get-ItemProperty command to find the version property. Below you can find short script based on Invoke-Command.

#Servers list
$Servers = "SQLServer01","SQLServer02"
           
#Checking SQL Server Native Client in registry
$Results = Icm -cn $Servers {Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\SQLNCLI11\CurrentVersion"} | Select-Object @{n='ServerName';e={$_.pscomputername}},Version

#Display results
$Results | Format-Table -AutoSize -Wrap

I hope that this was informative for you 🙂 See you in next articles.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.