Powershell Microsoft.win32.registrykey Openremotebasekey Credentials

As an IT pro I frequently need to read and write to registry keys on remote computers, either ad-hoc or via script. Sure I could use Regedit, or RDP to the server in question, but that involves a lot of clicking, and to be honest, moving my right hand to my mouse seems like such hard work 🙂

  1. Powershell Openbasekey
  2. Registrykey
  3. Registrykey Class
  4. Openremotebasekey Powershell

I though I’d show you a number of ways of doing this, as well as their limitations, as well as my personal favourite.

Option 1 – Get-ItemProperty

The Powershell cmdlet Get-ItemProperty can be used in conjunction with Invoke-Command to execute a command on a remote computer.

Powershell Microsoft.win32.registrykey Openremotebasekey Credentials Rating: 4,4/5 641 reviews I'm trying to write an application that will get some registry values from a remote computer. The user can provide a hostname or IP in a string and should be getting a registry value displayed on their screen. PowerShell connects to remote systems using the Windows Remote Management (WinRM) service. This would need to be configured on the remote systems for this script to function correctly. In my environment we have a GPO that enables this on all of the servers. Openremotebasekey Credentials I'm trying to write an application that will get some registry values from a remote computer. The user can provide a hostname or IP in a string and should be getting a registry value displayed on their screen.

Powershell Microsoft.win32.registrykey Openremotebasekey Credentials
2
$reg=[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine','Server01')
$subkey=$reg.OpenSubKey('SOFTWAREMicrosoftWindows NTCurrentVersion')

This is more likely to work as it is not reliant on WsMan being configured. However, it does require the RemoteRegistryservice to be running on the target computer. Which, by default is not. Also, there is no way to specify alternatecredentials, which can present a few problems depending on the computer you are talking to. e.g. non domain-joined machines mounted on the back of a 42″ LED TV mounted 5 meters off the floor… Quite a specific example there.

Microsoft.win32.registrykey

Option 3 (preferred) – WMI

My final and preferred option is using WMI. They beautiful thing about this method is WMI is typically available (I’m my experience) in most environments, also it accepts alternative credentials and is not reliant on the RemoteRegistry service.

Registrykey

2
$pass=ConvertTo-SecureString'Password'-AsPlainText-Force
$cred=New-Object-TypeName System.Management.Automation.PSCredential-ArgumentList$user,$pass
RegistrykeyC# registrykey

You can view all the required methods of the StdRegProv WMI class on MSDN here: https://msdn.microsoft.com/en-us/library/aa393664(v=vs.85).aspx

Registrykey Class

The only downside to this option was it took me a while to stumble across it!

Openremotebasekey Powershell

I hope this is of use , thanks for taking the time to read my blog!