What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Azure AD Connect Last Dir Sync - EXE/Script Advanced sensor

Votes:

0

Hi folks

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[0]

$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>"

azure exe prtg script

Created on Aug 4, 2022 6:30:18 AM



6 Replies

Votes:

0

Hello Rene,

Thank you for the post, can you try explicitly emptying "$output" at the beginning of the script?

Regards. Oscar

Created on Aug 9, 2022 1:30:05 PM by  Oscar Chavarria [Paessler Technical Support]



Votes:

0

Hi Oscar,

the same result. It looks like the sensor is just counting up. It counts up to 59 every hour and then drops down to 2 and starts over.

Regards, René

Created on Aug 10, 2022 11:55:47 AM



Votes:

0

Hello Rene,

If you run the script several times without PTRG in the picture does it show the right data?

What does it look like after adding the emptying section at the beginning?

To investigate further we also need to check sensor settings and need screenshots, I recommend you to open a ticket by reaching out to [email protected]

Created on Aug 12, 2022 10:36:39 PM by  Oscar Chavarria [Paessler Technical Support]



Votes:

0

The problem was solved during ticket processing. But anyway, I would like to announce the result here in case someone else encounters the problem.

The problem was that the PRTG service or even the PRTG user account that started the query on the sample did not get the certificate. The solution is simple. In the script, the certificate must first be read and then processed.

$CertThumbprint = "1234567890" $cert = Get-ChildItem Cert:\LocalMachine\My\$CertThumbprint

Connect-MgGraph -TenantId "xxx" -ClientID "xxx" -Certificate $cert

Created on Sep 2, 2022 5:56:47 AM



Votes:

0

Hello Rene,

Thank you for letting us know.

Regards, Oscar

Created on Sep 2, 2022 6:20:53 PM by  Oscar Chavarria [Paessler Technical Support]



Votes:

0

Hi Oscar, no problem

Created on Sep 19, 2022 4:57:44 AM

Last change on Sep 22, 2022 3:19:19 PM by  Luis Quesada (Paessler Technical Support)




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.