What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
300.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Custom EXE script

Votes:

0

Your Vote:

Up

Down

Hi there, I'm trying to find if a user is still using his VM by pulling his last logon and I'm having trouble with the output. When I run it in PS it works as expected, but in Prtg it only shows the message text without the date of last loogin. Here's the code :

Import-Module ActiveDirectory

$value=1 $server=$env:COMPUTERNAME $LogonDate=Get-ADComputer $server -Properties LastLogonDate | select -ExpandProperty LastLogonDate $LogonDateString=$LogonDate.ToString() $DaysPassed=(New-TimeSpan -Start $LogonDate -End (Get-Date)).Days if ($DaysPassed -gt 60 ) {$value=0 $message="Vm was not used for more then 60 days, last Logon was on " + $LogonDateString} else { if ($DaysPassed -le 60 ){ $value=1 $message="Vm is in use, last Logon was on " + $LogonDateString}}

Write-Host @" <prtg> <result> <channel>Vm in use</channel> <value>$value</value> </result>

<text>$message</text> </prtg> "@

custom-sensor exexml login

Created on May 21, 2020 4:44:38 AM by  claude (0) 1



3 Replies

Votes:

0

Your Vote:

Up

Down

Dear claude,

for debugging, please go to the sensor settings and enable "Write Exe result to disk". After the next scan, find the logs in "C:\ProgramData\Paessler\PRTG Network Monitor\Logs\sensors".

You will probably see a Powershell error message. Please check if it helps to change the security context in the sensor settings (probe context or Windows credentials).

Created on May 21, 2020 1:09:41 PM by  Arne Seifert [Paessler Support]



Votes:

0

Your Vote:

Up

Down

I already checked the log and also changed security context with no luck.

If I run the script in Powershell, I get the desired result :

<text>Vm is in use, last Logon was on 5/19/2020 2:21:21 AM</text> </prtg>

but in PRTG I get:

"Vm is in use, last Logon was on" without the date .

Created on May 22, 2020 8:42:31 AM by  claude (0) 1



Votes:

0

Your Vote:

Up

Down

Dear claude,

in this case, expand the script and implement debug output. Please don't write the debug log into the script folder, as that one is protected, rather use C:\Temp for output.

For example, please write the full output of Get-ADComputer to that file, so you can identify where the script execution is going wrong.

For analysis, please also run the script manually from the 32-bit Powershell to see if you get the result, because PRTG calls the 32-bit Powershell.

Created on May 22, 2020 1:23:18 PM by  Arne Seifert [Paessler Support]



Please log in or register to enter your reply.


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.