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

2.6k Views Asked by At

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()
}
0

There are 0 best solutions below