I have tried many windows updates script and found the following that suits our needs:
https://exchange.nagios.org/directory/P ... ll/details
when on Windows 2016 I run the script it perfectly runs, but when ran as plugin from NCPA, the test-path on the HKLM...\RebootRequired will always fail so it won't notify on pending reboots.
it seems like I am able to browse the HKLM via NCPA only up to HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\ but it is unable to find the WindowsUpdate key even tho it exists.
these the various steps I tried:
- I tried to run the service "NCPA Listener" as a local admin on the server, I can confirm the Powershell script runs with that user too, but still unable to access the key
- I tried to change the ExecutionPolicy to Unrestricted and confirmed it was by getting the result of Get-ExecutionPolicy from the plugin but still unable to access the key
- I tried on a couple of different other server with 2016, and never able to access the key.
- I changed the script a little, instead of using Test-Path I tried the Get-ChildItem in order to get an error message, and this is the error message:
Code: Select all
Warning
Unrestricted
Get-ChildItem : Cannot find path 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows
\\CurrentVersion\\WindowsUpdate\\Auto Update\\RebootRequired' because it does not
exist.
At C:\\Program Files (x86)\\Nagios\\NCPA\\plugins\\check_windows_updates.ps1:97
char:1
+ Get-ChildItem -Path "HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (HKEY_LOCAL_MACH...\\RebootRequir
ed:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetCh
ildItemCommand
Updates: 0 critical, 1 optionalCode: Select all
updates installed, reboot required