I want to monitor the lastdirsync status of Azure AD Connect with PRTG. For this I have written a ps1 script and get the minutes of the last sync correctly output in integer numbers. Now when I output the script in PRTG, PRTG never gives me the correct number. Either the number counts up after each update or the number is arbitrary.
If I fill the variable in the script for output to PRTG with a simple 1+1 calculation, the result is also correct in PRTG. I have a lot of scripts running that give me numbers. Only with the error I just do not come further.
Maybe someone here has an idea.
Here is the script:
$certificate = "xxx" $appid = "xxx" $tenantid = "xxx"
Connect-MgGraph -CertificateThumbprint $certificate -ClientId $appid -TenantId $tenantid
$lastDirSync = Get-MgOrganization | select OnPremisesLastSyncDateTime
$lastDirSyncCut = $lastDirSync.OnPremisesLastSyncDateTime
$CurrentDateandTime = get-date $Minutes = ($lastDirSyncCut - $CurrentDateandTime).Minutes
$output = [math]::Abs($Minutes)
"<prtg>" " <result>" " <channel>Last Directory Sync in Min</channel>" " <value>$output</value>" " </result>" "</prtg>"