dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

Get-SqlServerKey - Quick test shows "No instances found. Skipping." for almost all the servers I try

Open dansqldba opened this issue 10 years ago • 4 comments

Never tried this cmdlet before and heard about it today, thought I'd give it a go. In my environment this doesn't seem to work for the majority of servers queried. It seems to be connecting to the remote registry on each server, for the most part, but there may be a problem with the way it detects instances?

Will do more tests.

dansqldba avatar Sep 21 '16 10:09 dansqldba

Do me a favor, Dan? Can you replace servername with one of your sql server (netbios) names?

$servername = "sql2014" $ipaddr = ([System.Net.Dns]::GetHostAddresses($servername)).IPAddressToString $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $ipaddr) $basepath = "SOFTWARE\Microsoft\Microsoft SQL Server" $instances = $reg.OpenSubKey("$basepath\Instance Names\SQL", $false) $instances -eq $null $instances[0].GetValueNames()

Tell if if anything is returned.

potatoqualitee avatar Sep 21 '16 10:09 potatoqualitee

The above code returned the following for all the servers I tried which failed using the cmdlet:

True Cannot index into a null array. At line:6 char:1

  • $instances[0].GetValueNames()
  • - CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    - FullyQualifiedErrorId : NullArray
    
    

I tried this code with a couple of the servers which worked in the cmdlet, which returned the instance name(s) as expected.

Digging a little further with help from @Splaxi it looks like this might have something to do with x86/x64 strangeness. Seems the only servers in my estate which return a result with this cmdlet are x86. Most of my estate is x64. I'm assuming your lab isn't x86, however?

dansqldba avatar Sep 21 '16 12:09 dansqldba

Further input from @MikeFal and @wsmelton in Slack suggests the registry is not a reliable way to find SQL instances. I certainly agree with that based on what I've seen of my own estate today!

  • In place upgrades can result in the registry key used by this cmdlet not being present
  • Issues during installation preventing the key being created will not cause the install to fail or the instance from working (certainly my case as everything is up and running!)
  • @MikeFal suggests services might be more reliable to look at (I think you've done this elsewhere in newer cmdlets?)
  • Suggestions from @wsmelton include netstat -b, searching for installed software, enumerator classes

My suggestion is for a new shared function, which could be used throughout the module, dedicated to all the weird and wonderful ways to detect SQL Server instances.

dansqldba avatar Sep 21 '16 13:09 dansqldba

It's not simply finding SQL instances, I need to registry path to decode the key because the key is in the registry. :|

A new Get-DbaSqlInstance which would be super cool! This should be different from Find-DbaSqlInstance which is more about mass sweeps and discovery.

potatoqualitee avatar Sep 21 '16 13:09 potatoqualitee