Reputation: 741
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
Upvotes: 0
Views: 1208
Reputation: 8889
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)
Upvotes: 1