- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2017 12:27 PM
Context: Discovering a Windows Server using WMI/Powershell.
I need to populate a field named u_patch_host from a value stored in the registry key
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\WUServer
In the WMI Fields related list to the WMI Probe: Windows - OS Information, I add a field with the WMI patch set to the registry key named above.
The package is set to "Global" and I'm unable to set it to "Core Automation". Don't know why.
I ran a discovery of a Windows Server and the probe returns a server name as expected.
But I can't access the value in the sensor to save it to the proper field in the current CI record.
Can you give me any advice? I can't even find an error in the log to debug this.
So I'm open to ideas and advice.
Thanks in advance for your help.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2018 09:13 AM
I ended up filing an question/incident on HI and have a solution.
I was very close in my trial and error attempts. Here is the code that actually works. Instead of pasting in the entire script of the sensor, most of which is OOB, I am providing the script sequence added which performs the function. I follow up with a couple of observations from my experiments.
The code fragment for retrieving the value of a registry key in the sensor named "Windows - OS Information"
// This code is to set the Patch Cycle followed by the Patch Server
// Reference: https://community.servicenow.com/message/787029#787029
var regKey = "HKEY_LOCAL_MACHINE.SOFTWARE.Policies.Microsoft.Windows.WindowsUpdate"; // need dots between the levels.
var node = g_disco_functions.findRegistryNode(result.Registry, regKey);
var patch_cycle = g_disco_functions.findNodeValueWithAttribute(node, "TargetGroup");
current.u_patch_cycle = patch_cycle;
Notes:
1. The registry key retrieved by the probe "Windows - OS Information" is:
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\TargetGroup
2. When invoking findRegistgryNode, format the key with the following ideas in mind.
- Replace the backslashes with dots ".".
- Exclude the final node name. This will be used in the invocation of findNodeValueWithAttribute.
3. store the resulting value in a field within the current object and it will be included in the CI record when it is updated.
As always, I'm happy to receive feedback from those more knowledgeable than myself. Especially about any corrections or omissions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2017 12:38 PM
First of all, I owe you an apology. I switched gears slightly from my first post to the third post, on Dec 14, 2017 2:01 PM. (the post with the full text of the sensor ).
In response to your attempt to access the keys on your computer, you may not find registry keys.
I think the keys were added by our sysadmins to track the patching process for each server.
There are 2 registry keys involved, WUServer and TargetGroup. In my first post, the source code shows me attempting to access the key "WUServer".
In my third post, the source code is attempting to get a value for the key "TargetGroup"
I'm attempting lots of "trial and error" and I inadvertently switched keys. However, if I can get one of these working, I can then get the other one too.
Now to answer your question about what kind of value should TargetGroup return? A text string looking like "Week_2".
Here's an image of the response from the probe:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2018 09:13 AM
I ended up filing an question/incident on HI and have a solution.
I was very close in my trial and error attempts. Here is the code that actually works. Instead of pasting in the entire script of the sensor, most of which is OOB, I am providing the script sequence added which performs the function. I follow up with a couple of observations from my experiments.
The code fragment for retrieving the value of a registry key in the sensor named "Windows - OS Information"
// This code is to set the Patch Cycle followed by the Patch Server
// Reference: https://community.servicenow.com/message/787029#787029
var regKey = "HKEY_LOCAL_MACHINE.SOFTWARE.Policies.Microsoft.Windows.WindowsUpdate"; // need dots between the levels.
var node = g_disco_functions.findRegistryNode(result.Registry, regKey);
var patch_cycle = g_disco_functions.findNodeValueWithAttribute(node, "TargetGroup");
current.u_patch_cycle = patch_cycle;
Notes:
1. The registry key retrieved by the probe "Windows - OS Information" is:
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\TargetGroup
2. When invoking findRegistgryNode, format the key with the following ideas in mind.
- Replace the backslashes with dots ".".
- Exclude the final node name. This will be used in the invocation of findNodeValueWithAttribute.
3. store the resulting value in a field within the current object and it will be included in the CI record when it is updated.
As always, I'm happy to receive feedback from those more knowledgeable than myself. Especially about any corrections or omissions.