Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, February 17, 2011 7:20 AM
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.http://www.virtualrealm.com.au - XNA Game Programming News and Resources from Downunder.
All replies (11)
Friday, February 18, 2011 3:03 AM ✅Answered
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 [email protected]
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
Thursday, February 17, 2011 7:41 AM
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.
Thursday, February 17, 2011 5:56 PM
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
Sunday, February 20, 2011 1:19 PM
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
Shay Levy [MVP]
PowerShay.com
PowerShell Toolbar
Monday, February 21, 2011 11:08 PM | 1 vote
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}
http://www.virtualrealm.com.au - XNA Game Programming News and Resources from Downunder.
Tuesday, February 22, 2011 4:03 PM
Correct, $host is an automatic variable. It is created and maintained by Windows PowerShell.
Shay Levy [MVP]
PowerShay.com
PowerShell Toolbar
Thursday, March 31, 2011 4:18 PM
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
** **
Thursday, March 31, 2011 4:22 PM
firewall or service not started?
can you connect remotely with regedit?
Tuesday, June 24, 2014 9:56 AM | 1 vote
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)
Tuesday, September 2, 2014 1:47 PM | 1 vote
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.
Saturday, April 11, 2015 7:45 AM
Hi Stejo,
You can use below command in powershell.
sc.exe \\XX.XX.XX.XX start "RemoteRegistry"
where XX.XX.XX.XX system IP.
Naveen Basati