Answered by:
Get Remote Registry value.

Question
-
is there a way to get value of a registry from remote computer..I am trying to values of these keys...
HKEY_LOCAL_MACHINE\SOFTWARE\MQUEST\ScriptEngine\Program\PrimaryScriptServer
HKEY_LOCAL_MACHINE\SOFTWARE\MQUEST\ScriptEngine\Program\SecondaryScriptServer
HKEY_LOCAL_MACHINE\SOFTWARE\MQUEST\ScriptEngine\Program\Server1
HKEY_LOCAL_MACHINE\SOFTWARE\MQUEST\ScriptEngine\Program\Server2
any help is greatly appreciated.Monday, May 4, 2009 2:09 PM
Answers
-
I understand. In your VBS code is shown that SOFTWARE\MQUEST\ScriptEngine\Program\ is Key path. However PrimaryScriptServer is not a key, but value. And code above retrives only names. If you want to get particular name value, you can use :
$strMachineName = 'MURBAMEXV004'
$objReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $strMachineName)
$objRegKey= $objReg.OpenSubKey("SOFTWARE\\MQUEST\\ScriptEngine\\Program" )
$objRegKey.GetValue("PrimaryScriptServer")
If I understand correctly, this code should work. And after this you can read data for values:
$strMachineName = 'MURBAMEXV004'
$objReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $strMachineName)
$objRegKey= $objReg.OpenSubKey("SOFTWARE\\MQUEST\\ScriptEngine\\Program" )
"PrimaryScriptServer", "SecondaryScriptServer", "Server1", "Server2" | %{
"Data for value " + $_
$objRegKey.GetValue("$_")
}
or place values to variable:
$values = "PrimaryScriptServer", "SecondaryScriptServer", "Server1", "Server2"
and query:
$values | %{
"Data for value " + $_
$objRegKey.GetValue("$_")
}
[тут могла быть ваша реклама] http://www.sysadmins.lv- Marked as answer by Vincent Hu Monday, May 18, 2009 2:16 AM
Monday, May 11, 2009 6:15 PM
All replies
-
Hi,
You can use:
$strMachineName = '.'
$objReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $strMachineName)
$objRegKey= $objReg.OpenSubKey("SYSTEM\\SOFTWARE\MQUEST\\ScriptEngine\\Program\\PrimaryScriptServer" )
$objRegkey.GetValueNames()
Hope it helps.
Grégory Schiro - PowerShell & MOF- Proposed as answer by Grégory Schiro Monday, May 4, 2009 3:24 PM
Monday, May 4, 2009 3:24 PM -
getting error here is the debug output
DEBUG: 1+ ./reg1.ps1
DEBUG: ! CALL script 'reg1.ps1'
DEBUG: 1+ $strMachineName = 'MURBAMEXV004'
DEBUG: ! SET $strMachineName = 'MURBAMEXV004'.
DEBUG: 2+ $objReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $strMachineName)
DEBUG: ! CALL method 'static Microsoft.Win32.RegistryKey OpenRemoteBaseKey(RegistryHive hKey, String machineName)'
DEBUG: ! SET $objReg = 'HKEY_LOCAL_MACHINE'.
DEBUG: 3+ $objRegKey= $objReg.OpenSubKey("SYSTEM\\SOFTWARE\MQUEST\\ScriptEngine\\Program\\PrimaryScriptServer" )
DEBUG: ! CALL method 'Microsoft.Win32.RegistryKey OpenSubKey(String name)'
DEBUG: ! SET $objRegKey = ''.
DEBUG: 4+ $objRegkey.GetValueNames()
DEBUG: 2+ if ($ErrorView -ne "CategoryView") {
DEBUG: 3+ $myinv = $_.InvocationInfo
DEBUG: ! SET $myinv = 'System.Management.Automation.InvocationInfo'.
DEBUG: 4+ switch -regex ($myinv.MyCommand.CommandType)
DEBUG: 24+ if ($myinv.MyCommand.Name)
DEBUG: 2+ if ($_.InvocationInfo) {
DEBUG: 3+ $posmsg = $_.InvocationInfo.PositionMessage
DEBUG: ! SET $posmsg = '
At C:\reg1.ps1:4 char:25
+ $objRegkey.GetValueNames( ...'.
DEBUG: 7+ if ($ErrorView -eq "CategoryView") {
DEBUG: 11+ $_.Exception.Message + $posmsg
You cannot call a method on a null-valued expression.
At C:\reg1.ps1:4 char:25
+ $objRegkey.GetValueNames( <<<< )Monday, May 4, 2009 3:36 PM -
IT is a Reg_SZ value i am trying to read if that helpsMonday, May 4, 2009 4:21 PM
-
Rahter than getting the value it would be enough to check if the said keys existMonday, May 4, 2009 4:27 PM
-
Hi,
Please have a read of these articlesPowerShell script to get remote registry key property
http://myitforum.com/cs2/blogs/yli628/archive/2008/12/11/powershell-script-to-get-remote-registry-key-property.aspxTuesday, May 5, 2009 6:41 AM -
$objRegKey= $objReg.OpenSubKey("SOFTWARE\\MQUEST\\ScriptEngine\\Program\\PrimaryScriptServer" )
one slash is missed. And remove SYSTEM in key path.
[тут могла быть ваша реклама] http://www.sysadmins.lv- Proposed as answer by Vadims PodansMVP Tuesday, May 5, 2009 8:05 AM
Tuesday, May 5, 2009 7:53 AM -
Still getting same errorTuesday, May 5, 2009 8:42 AM
-
please, show your code.
[тут могла быть ваша реклама] http://www.sysadmins.lvTuesday, May 5, 2009 2:00 PM -
$strMachineName = 'MURBAMEXV004'
$objReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $strMachineName)
$objRegKey= $objReg.OpenSubKey("SOFTWARE\\MQUEST\\ScriptEngine\\Program\\PrimaryScriptServer" )
$objRegkey.GetValueNames(Friday, May 8, 2009 11:18 AM -
this fine works for me. Are you sure that this key exist in HKLM\SOFTWARE\MQUEST\ScriptEngine\Program\PrimaryScriptServer on MURBAMEXV004?
[тут могла быть ваша реклама] http://www.sysadmins.lvFriday, May 8, 2009 5:37 PM -
PS C:\> ./reg1.ps1
You cannot call a method on a null-valued expression
At C:\reg1.ps1:4 char:25
+ $objRegkey.GetValueNames <<<< ()
i have check that machine even in 005 the key exist...I can pull if from this VBS..
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\MQUEST\ScriptEngine\Program\"
strValueName = "PrimaryScriptServer"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
verFn = StrValueMonday, May 11, 2009 2:57 PM -
I understand. In your VBS code is shown that SOFTWARE\MQUEST\ScriptEngine\Program\ is Key path. However PrimaryScriptServer is not a key, but value. And code above retrives only names. If you want to get particular name value, you can use :
$strMachineName = 'MURBAMEXV004'
$objReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $strMachineName)
$objRegKey= $objReg.OpenSubKey("SOFTWARE\\MQUEST\\ScriptEngine\\Program" )
$objRegKey.GetValue("PrimaryScriptServer")
If I understand correctly, this code should work. And after this you can read data for values:
$strMachineName = 'MURBAMEXV004'
$objReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $strMachineName)
$objRegKey= $objReg.OpenSubKey("SOFTWARE\\MQUEST\\ScriptEngine\\Program" )
"PrimaryScriptServer", "SecondaryScriptServer", "Server1", "Server2" | %{
"Data for value " + $_
$objRegKey.GetValue("$_")
}
or place values to variable:
$values = "PrimaryScriptServer", "SecondaryScriptServer", "Server1", "Server2"
and query:
$values | %{
"Data for value " + $_
$objRegKey.GetValue("$_")
}
[тут могла быть ваша реклама] http://www.sysadmins.lv- Marked as answer by Vincent Hu Monday, May 18, 2009 2:16 AM
Monday, May 11, 2009 6:15 PM -
Why make it so hard when it can be done so easy :-)
reg query "\\<computername>\HKLM\SOFTWARE\MQUEST\ScriptEngine\Program\PrimaryScriptServer
Check the "reg query /?" command for details
To get info from several machines this command can be used:
for %i in (server1,server2,server3) do reg query "\\%i\HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v SessionPoolSize
This is an example to get/query a given registry key value for all servers in a Terminal Server farm (run from a TS):
for /f "skip=3 delims=* " %i in ('qfarm /servers') do @echo --------------- %i --------------------- & reg query "\\%i\HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v SessionPoolSize
Have fun,
Tord BergsetFriday, June 19, 2009 4:18 PM -
So reg query \\computername\hklm:\.." is erroring out? Saying invalid computer name. Is there no way to use get-itemproperty remotely?
Cheers.
JCtech1123, Cheers
Wednesday, August 8, 2012 11:13 PM -
The command should work as long as you can ping your servername.
You can also use server IP like this
\\10.10.10.20\HKLM\Software...
In your example above you have ":" after HKLM .. that is incorrect I believe
/Tord
/Tord
Thursday, August 9, 2012 7:47 AM -
Yeah, the ":" after HKLM is powershell-ese for "use this other provider" - without that a registry path would be indistinguishable from a relative or absolute path or UNC.
"reg", or, less ambiguously, "reg.exe" needs no such distinction as registry paths are the only things it deals with.
Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.
Thursday, August 9, 2012 5:31 PM -
Ah yes! I removed the ":" and it worked. I also found that I can use a variable for \\<machine name>. This way I can query several machines at same time.
Thx everyone!
JCtech1123, Cheers
- Proposed as answer by JCtech1123 Tuesday, August 28, 2012 12:57 AM
Tuesday, August 28, 2012 12:57 AM