title: Featch Installed SQL instance names on multiple servers
body: <p>I writing this to get the list of installed instance on a remote sql server but it was failing  with below error I am going achieve this as follows</p>
  <ol>
  <li>Read the list of servers names from my central db server</li>
  <li>create a function that takes servers from step1 retrieved.</li>
  </ol>
  <h1>Code</h1>
  <pre><code># -- Get the patch servers from central server  function
  get-patchservers {
      # -- Where is your central patching database located?
      $sql_inst   = Read-Host &quot;SQL instance hosting Patching DB; default: Severname\SQL201201&quot;
      # -- Default patching control server to &quot;ServerName\SQL201201&quot;
      if($sql_inst -eq &quot;&quot;) {$sql_inst=&quot;Severname\SQL201201&quot;}
      # -- What's the name of your central patching database?
      $sql_db     = Read-Host &quot;Name of Patching DB; default:patchdb&quot;
      # -- Default datatabase for patching db
      if($sql_db -eq &quot;&quot;) {$sql_db=&quot;patchdb&quot; }
      # -- T-SQL to feacth server name from cerntral db
      $Tsql = &quot;SELECT svr_name  FROM server&quot;
      $ServerList = Invoke-Sqlcmd -Query $Tsql -ServerInstance $sql_inst -Database $sql_db    #return $ServerList   
  
      foreach($Server in $ServerList) {
          ECHO $Server
          $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Server)
          $regKey= $reg.OpenSubKey(&quot;SOFTWARE\\Microsoft\\MicrosoftSQL Server\\Instance Names\\SQL&quot; )
          $instances = $regkey.GetValueNames()
          $instances
      }
  }    
  </code></pre>