0

I am trying to query a registry path of a remote server:

"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired"

This contains a list of all updates that are pending a reboot (REG_DWORD), and perhaps some dates of some kind. I am interested in the number of pending updates only.

Performing the following PS cmdlet, I do not get the result I expect in querying the reg path:

       $Computer = "Server01" 
       $HKLM = [UInt32] "0x80000002" 
       $WMI_Reg = [WMIClass] “\\$Computer\root\default:StdRegProv” 
       $RegRR = $WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired")

$RegRR = 
__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     : 
__DYNASTY        : __PARAMETERS
__RELPATH        : 
__PROPERTY_COUNT : 2
__DERIVATION     : {}
__SERVER         : 
__NAMESPACE      : 
__PATH           : 
ReturnValue      : 0
sNames           : 

However, as a test, if I query the path one key before this, excluding "\RebootRequired" then this works and I can then query the sValues.

$RegRR = $WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\

__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     : 
__DYNASTY        : __PARAMETERS
__RELPATH        : 
__PROPERTY_COUNT : 2
__DERIVATION     : {}
__SERVER         : 
__NAMESPACE      : 
__PATH           : 
ReturnValue      : 0
sNames           : {Power, RequestedAppCategories, Results, RebootRequired...}

Ultimately, I wish to query this reg key in order to return back the number of updates pending a reboot, existing DWORD records. There is a RebootRequiredSince date, which at first could be useful, but found out that not all of our servers have this (mix of 2008 R2 and 2012).

Any ideas?

Thanks

TOGEEK
  • 711
  • 4
  • 15
  • 34
  • Hi, you can try with this other method : http://stackoverflow.com/questions/15069130/get-remote-registry-value – sodawillow Jun 23 '16 at 13:51

1 Answers1

1

Make sure you enable the RemoteRegistry Service on the target machine, then you can try:

$Computer = "RemoteComputerName"
$RootKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine",$Computer)
$SubKey = $RootKey.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\RebootRequired")

To get all the available values you can do:

$SubKey.GetValueNames()

To get all the Subkey Names:

$SubKey.GetSubKeyNames()

To get Specific value:

$SubKey.GetValue("ValueName")

To Get the Default Key Value:

$SubKey.GetValue($null)
Avshalom
  • 8,657
  • 1
  • 25
  • 43
  • Yes I have done that except I used GetSubKeyNames() which returned null, and not GetValueNames(), and now I get the results I need thanks! – TOGEEK Jun 23 '16 at 15:24