title: OpenRemoteBaseKey() credentials
body: <p>I'm attempting to use powershell to access a remote registry like so:</p>
  
  <pre><code>$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $server)
  $key = $reg.OpenSubkey($subkeyPath)
  </code></pre>
  
  <p>Depending on some factors that I'm not yet able to determine I either get</p>
  
  <blockquote>
    <p>Exception calling "OpenSubKey" with "1" argument(s): "Requested registry access is not allowed."</p>
  </blockquote>
  
  <p>Or</p>
  
  <blockquote>
    <p>System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
       at Microsoft.Win32.RegistryKey.Win32ErrorStatic(Int32 errorCode, String str)
       at Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(RegistryHive hKey, String machineName)</p>
  </blockquote>
  
  <p>It seems pretty clear that this is because the user I'm running the powershell script as doesn't have the appropriate credentials to access the remote registry. I'd like to be able to supply a set of credentials to use for the remote registry access, but I can find no documentation anywhere of a way to do this. I'm also not clear on exactly where to specify <em>which</em> users are allowed to access the registry remotely.</p>