Powershell Microsoft.win32.registrykey Openremotebasekey Credentials



Assigning Permissions to a Registry Key. Click the key that you want to assign permissions. On the Edit menu, click Permissions. Click the group or user name that you want to work with.

  • The local machine registry is opened if machineName is String.Empty.The requested key must be a root key on the remote machine, and is identified by the appropriate RegistryHive value. In order for a key to be opened remotely, both the server and client machines must be running the remote registry service, and have remote administration enabled.
  • Hi, I am trying to recurse through a remote registry key path and search through it for a value name and get the value data.Hence i need to give it atleast a subkey to start from so as to avoid searching time delay through many nodes.
  • Remote Registry service. On the remote host, there is a Remote Registry service to check. You can start the Windows Services list GUI with the command Services.msc, or you can click the Services icon from the Administrative Tools group icon from Control Panel: - The third column is startup type - make sure it is set to automatic.
  • The nice thing about this command is you can also specify alternate credentials. However, it does require that WsMan is correctly configured for powershell remoting to work. Which, 9 times out of 10 in most environments it is not. Option 2 – The Microsoft.Win32.RegistryKey Class.

I was tasked with writing a script to find a single registry key on all of the server for a domain that my team manages. So after getting the key that we need to know the value of, I put a script together. The script will first check to see if the server is online, and if it is then the scripts looks at the registry to find the key and records the value. Then generates a report of the keys that were found.

The beauty of this script, is that it to took about as much time to find the information on the first server as it did to write this script. So with needing to find this information on 40+ servers, it is well worth writing. The rule of thumb, if you have to do it more than twice, script it.

– Stuart

Discussion

Although PowerShell does not directly let you access and manipulate the registry of a remote computer, it still supports this by working with the .NET Framework. The functionality exposed by the .NET Framework is a bit more developeroriented than we want, so we can instead use a script to make it easier to work with.

Example 188 lets you set the value of a property on a given remote registry key. In order for this script to succeed, the target computer must have the remote registry service enabled and running.

Example 188. SetRemoteRegistryKeyProperty.ps1

############################################################################## ## ## SetRemoteRegistryKeyProperty.ps1 ## ## Set the value of a remote registry key property ## ## ie: ## ## PS >$registryPath = ## 'HKLM:softwareMicrosoftPowerShell1ShellIdsMicrosoft.PowerShell' ## PS >SetRemoteRegistryKeyProperty LEEDESK $registryPath ` ## 'ExecutionPolicy' 'RemoteSigned' ## ##############################################################################

param( $computer = $(throw 'Please specify a computer name.'), $path = $(throw 'Please specify a registry path'), $property = $(throw 'Please specify a property name'), $propertyValue = $(throw 'Please specify a property value') )

Powershell Opensubkey Getvalue

## Validate and extract out the registry key if($path match '^HKLM:(.*)') {

Openremotebasekey Powershell

$baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey

('LocalMachine', $computer) } elseif($path match '^HKCU:(.*)') {

$baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey ('CurrentUser', $computer) }

Example 188. SetRemoteRegistryKeyProperty.ps1 (continued)

Powershell Microsoft.win32.registrykey Openremotebasekey CredentialsPowershell Microsoft.win32.registrykey Openremotebasekey CredentialsMicrosoft.win32.registrykey

else { WriteError ('Please specify a fullyqualified registry path ' + '(i.e.: HKLM:Software) of the registry key to open.') return }

Powershell

## Open the key and set its value $key = $baseKey.OpenSubKey($matches[1], $true) $key.SetValue($property, $propertyValue)

## Close the key and base keys $key.Close() $baseKey.Close()