2

I am trying to access through PowerShell the registry of multiple remote servers (whose names are read from a text file) in order to gather information about SQL Server instances installed in a specific server.

Here are some additional details:

  1. The user account I am using to access the remote servers is an administrator in those servers
  2. I've checked if the remote registry service is running on each server. It is running.

The error that keeps on showing is:

Exception calling "OpenRemoteBaseKey" with "2" argument(s): "Attempted to perform an unauthorized operation.

Here is a part of my script:

$VMs = get-content C:\VMs\patchtestingvms.txt
foreach($VM in $VMs)
{
    $CompName = $VM.Trim()
    $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $CompName)
    $regKey= $reg.OpenSubKey("SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL" )         
    $instances = $regkey.GetValueNames()
}
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Famela Canico
  • 31
  • 1
  • 4
  • Does the same query work with `reg.exe`? Like so, `reg query "\\computer\hklm\software..."` (Remember to use the same execution account in both cases.) – vonPryz Dec 02 '14 at 08:32
  • can you kindly elaborate more on this method? I'm kind of new to PowerShell. Thank you – Famela Canico Dec 02 '14 at 09:41
  • Reg.exe is [`well documented`](http://technet.microsoft.com/en-us/library/cc742028.aspx). – vonPryz Dec 02 '14 at 10:44

0 Answers0