Verify if a Registry Key exists on Remote Machines
I am looking for a simple script to check if a registry key exists on remote machines. I have the code to perform an action based on a list of machines (Which has been done and published hundreds of times). What I am looking for now is a way to check the existance of a key on a remote machine.
February 17th, 2011 7:20am

Maybe this help you:
http://code.msdn.microsoft.com/PSRemoteRegistry

Example:

Get-RegValue -ComputerName “10.10.10.2” -Key "SYSTEM\CurrentControlSet\Control\Terminal Server" -Value fDenyTSConnections

If don't exists then return nothing.

Free Windows Admin Tool Kit Click here and download it now
February 17th, 2011 7:41am

Hi

 

I had to do something similar have a look at my code here … http://gallery.technet.microsoft.com/scriptcenter/8b49a002-f051-4014-99d7-33fc4b80c35e

Basically using [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey and enumerating all the values beneath it to find a key with certain values in it.

Hope it helps.

 

J

 

February 17th, 2011 5:56pm

Hi,

 

Thanks for posting in Microsoft TechNet forums.

 

Based on my research, try the following sample powershell script:

 

$host = “RemoteComputer”

$Hive = [Microsoft.Win32.RegistryHive]“LocalMachine”;

$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($Hive,$host);

$ref = $regKey.OpenSubKey(“SOFTWARE\Microsoft\windows\CurrentVersion\Uninstall”);

if (!$ref) {$false}

else {$true}

 

Resource:

 

Check for remote registry existance with Powershell

http://techibee.com/sysadmins/check-for-remote-registry-existance-with-powershell/265

 

Best Regards

Dale Qiao
TechNet Subscriber Support in forum. If you have any feedback on our support, please contact tngfb@microsoft.com

 

Free Windows Admin Tool Kit Click here and download it now
February 18th, 2011 3:03am

The PSRemoteRegistry has two test functions you can use:

Test-RegKey and Test-RegValue


You can download it from here: http://code.msdn.microsoft.com/PSRemoteRegistry

February 20th, 2011 1:19pm

Going through the Script this morning and I was having some problems with it. I have found that $host is a constant, Here is the changed script for those that follow.

# Script to verify the existance of a Registry Key on Remote Machines

$remoteComputer= "DevelopmentMachine"

$regkey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $remoteComputer) 
$ref = $regKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");

if (!$ref) {$false}
else {$true}
Free Windows Admin Tool Kit Click here and download it now
February 21st, 2011 11:08pm

Correct, $host is an automatic variable. It is created and maintained by Windows PowerShell.

February 22nd, 2011 4:03pm

I'm reading the registry in this same way. my script works on one win serv 2k8 r2 box, but not another. when it fails on this other win 2k8 box i get:

Exception calling "OpenRemoteBaseKey" with "2" argument(s): "The network path was not found.

"

At C:\Users\myprofile\AppData\Local\Temp\7a9e6036-9a2b-49aa-aa42-7157a933e148.ps1:43 char:65

+ $ProductName = ([Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey <<<< ('LocalMachine', $hostname).OpenSubKey('SOFTWARE\Microsoft\Windows NT\Cu

rrentVersion').GetValue('ProductName'))

+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException

+ FullyQualifiedErrorId : DotNetMethodException

 

Any ideas as to why it errors with the above on one win2k8r2 box, and not on the other?

 

Thanks

 

Free Windows Admin Tool Kit Click here and download it now
March 31st, 2011 4:18pm

firewall or service not started?

can you connect remotely with regedit?

March 31st, 2011 4:22pm

This means that the remoteregistry service is stopped.

You can enable this by group policy, or earlier on in the script run this command:

Get-Service -ComputerName $computer -Name RemoteRegistry |Start-Service

(where $computer is the name of the computer)

Free Windows Admin Tool Kit Click here and download it now
June 24th, 2014 9:56am

Yes this really means that RemoteRegistry is stopped or Disabled.

So use below sequence to set it automatic or manual (This example set it to automatic) and then start it : 

$computer= "Hostname of Remote machine"
Set-Service -ComputerName $computer -Name RemoteRegistry -StartupType Automatic
Get-Service -ComputerName $computer -Name RemoteRegistry | Start-Service

(First command line is about the hostname of the computer you are targetting)

Thanks to all for contribution.

September 2nd, 2014 1:47pm

Hi Stejo,

You can use below command in powershell.

sc.exe \\XX.XX.XX.XX start "RemoteRegistry"

where XX.XX.XX.XX system IP.

Free Windows Admin Tool Kit Click here and download it now
April 11th, 2015 3:48am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics