Same sensor from before (https://helpdesk.paessler.com/en/support/solutions/articles/86773-script-returning-a-string-value) but I'm having trouble getting my time elapsed sensor to actually display the value I'm passing to it.

$module = (Join-Path $(Split-Path $env:SMS_ADMIN_UI_PATH) ConfigurationManager.psd1)

Import-module $module

$SiteCode = Get-PSDrive -PSProvider CMSITE
Set-Location -Path "$($SiteCode.Name):\"

$syncResult = get-cmsoftwareupdatesyncstatus

$timestamp = get-date
$timeDiff = $timestamp - $syncResult.lastSuccessfulSyncTime

$xmlOutput = '<?xml version="1.0" encoding="UTF-8" ?><prtg>'

$xmlOutput = $xmlOutput + "<result>
<channel>Sync Code</channel>
<value>" + $syncResult.lastSyncErrorCode + "</value>
<unit>Absolute</unit>
<limitmode>1</limitmode>
<LimitMaxError>0</LimitMaxError>
<LimitErrorMsg>SCCM Error: Sync with Microsoft Update Catalog failed.  Code: " + $syncResult.lastSyncErrorCode + "</LimitErrorMsg>
</result>
<result>
<channel>Successful Sync Age</channel>
<value>" + $timeDiff.TotalHours + "</value>
<unit>TimeHours</unit>
<float>1</float>
<DecimalMode>All</DecimalMode>
<limitMode>1</limitMode>
<limitMaxError>170</limitMaxError>
<LimitErrorMsg>SCCM has not been able to sync with Microsoft update in 7 days.</LimitErrorMsg>
</result>
"

$xmlOutput = $xmlOutput + "</prtg>"
$xmlOutput

When I tweak the channel settings, they are reflected in PRTG (converting the channel to TimeHours, for example). However the value is always zero. If I run the script manually in Powershell the totalHours property seems to be correctly displayed within the 'value' tag.


Article Comments

Hi there,

Please activate the "Write EXE result to disk" option in the sensor's settings and post the log files (Result of Sensor XXX.Data.txt and Result of Sensor XXX.txt) located on the corresponding probe under "C:\ProgramData\Paessler\PRTG Network Monitor\Logs (Sensors)".

Best regards.


Oct, 2019 - Permalink

You can close this. I turned on the EXE results for another SCCM-related sensors I am developing and figured out the problem for both.

When I was testing under my user account, the values were being generated. But when the user that PRTG was configured to use to run the sensor tried to execute the SCCM-specific cmdlets, some of them failed because it couldn't respond with "always allow" when Powershell prompted the 'user' to confirm that the module was trusted. Once I did that, both scripts began to display their values appropriately.

If I submit these sensors to Script World, I'll be sure to note this arcane requirement!


Oct, 2019 - Permalink