Hi Erhard,
here is the script which collect Infos via Powershell about the Windows Updates distributed by SCCM.
The Script needs the following options set under Settings.
hand over the Hostname:
Parameter: -computer %host
run the Powershell Script in user security context with an User which has the required rights.
Security context: Use the access data for Windows on the parent device
Important on the PRTG Node:
If you want to run the Powershell Script without digital signature you had to allow this on the PRTG Node unter windows Powershell.
To allow run all Powershell Scripts on the Host open an Powershell and execute the following command:
- Set-ExecutionPolicy unrestricted
## define passed parameters
param(
[String]$computer="localhost"
)
## definition of variables
## Pending Boot for Updates (id 8)
$count_boot_pending=0
## Updates still to be installed (id 6)
$count_Updates_to_install=0
## Updates that failed (id 13)
$count_Updates_error=0
## Updates installing (id 7)
$count_Updates_installing=0
## Updates downloading (id 5)
$count_Updates_downloading=0
## Updates other (rest of the ids)
$count_Updates_unknown_state=0
## Update name or KB article
$update_KB_ids = "Server Up To Date"
## Load variable updates with data from the target system
$updates = get-wmiobject CCM_SoftwareUpdate -namespace "ROOT\ccm\ClientSDK" -ComputerName $computer
## Analyze update states and write to Variables
ForEach($var in $updates){
if($var.EvaluationState -eq 8 ){
$count_boot_pending=$count_boot_pending+1
}
elseif($var.EvaluationState -eq 6 ){
$count_Updates_to_install=$count_Updates_to_install+1
}
elseif($var.EvaluationState -eq 13 ){
$count_Updates_error=$count_Updates_error+1
}
elseif($var.EvaluationState -eq 7 ){
$count_Updates_installing=$count_Updates_installing+1
}
elseif($var.EvaluationState -eq 4 ){
$count_Updates_downloading=$count_Updates_downloading+1
}
else{
$count_Updates_unknown_state=$count_Updates_unknown_state+1
}
if ($update_KB_ids -eq "Server Up To Date"){
$update_KB_ids = "Pending Updates: KB" + $var.ArticleID
}
else{
$update_KB_ids += " / KB" + $var.ArticleID
}
}
## create XML output for PRTG
Write-Host "<?xml version=`"1.0`" encoding=`"Windows-1252`" ?>"
Write-Host "<prtg>"
Write-Host "<result>"
Write-Host "<channel> Updates Pending </channel>"
write-host "<unit> Quantity </unit>"
Write-Host "<value>" $updates.count "</value>"
Write-Host "</result>"
Write-Host "<result>"
Write-Host "<channel> Boot Pending </channel>"
write-host "<unit> Quantity </unit>"
Write-Host "<value>" $count_boot_pending "</value>"
Write-Host "</result>"
Write-Host "<result>"
Write-Host "<channel> wait for install </channel>"
write-host "<unit> Quantity </unit>"
Write-Host "<value>" $count_Updates_to_install "</value>"
Write-Host "</result>"
Write-Host "<result>"
Write-Host "<channel> Error </channel>"
write-host "<unit> Quantity </unit>"
Write-Host "<value>" $count_Updates_error "</value>"
Write-Host "</result>"
Write-Host "<result>"
Write-Host "<channel> currently installing </channel>"
write-host "<unit> Quantity </unit>"
Write-Host "<value>" $count_Updates_installing "</value>"
Write-Host "</result>"
Write-Host "<result>"
Write-Host "<channel> downloading </channel>"
write-host "<unit> Quantity </unit>"
Write-Host "<value>" $count_Updates_downloading "</value>"
Write-Host "</result>"
Write-Host "<result>"
Write-Host "<channel> unknown state </channel>"
write-host "<unit> Quantity </unit>"
Write-Host "<value>" $count_Updates_unknown_state "</value>"
Write-Host "</result>"
Write-Host "<text>"
write-host $update_KB_ids
Write-Host "</text>"
Write-Host "</prtg>"
<#
CCM_SoftwareUpdate reference
https://msdn.microsoft.com/en-us/library/jj155450.aspx
Value State
0 ciJobStateNone
1 ciJobStateAvailable
2 ciJobStateSubmitted
3 ciJobStateDetecting
4 ciJobStatePreDownload
5 ciJobStateDownloading
6 ciJobStateWaitInstall
7 ciJobStateInstalling
8 ciJobStatePendingSoftReboot
9 ciJobStatePendingHardReboot
10 ciJobStateWaitReboot
11 ciJobStateVerifying
12 ciJobStateInstallComplete
13 ciJobStateError
14 ciJobStateWaitServiceWindow
15 ciJobStateWaitUserLogon
16 ciJobStateWaitUserLogoff
17 ciJobStateWaitJobUserLogon
18 ciJobStateWaitUserReconnect
19 ciJobStatePendingUserLogoff
20 ciJobStatePendingUpdate
21 ciJobStateWaitingRetry
22 ciJobStateWaitPresModeOff
23 ciJobStateWaitForOrchestration
#>
copy this Code to an File and save it under ..\PRTG Network Monitor\Custom Sensors\EXEXML\ e.g. custom_SCCM.ps1
Now the script ( Filname ) could be selected when you create a new xmlEXESensor. Do not forget to enter the parameters from above.
Screenshots
I hope that is useful for someone.
Kind Regards
Björn
Add comment