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

Powershell script not executing (PE018)

Votes:

0

I'm trying to run the following Powershell script automatically in PRTG.

$password = Get-Content C:\securestring.txt | convertto-securestring
$username = 
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://prod-exch1.prod.local/PowerShell/ -Credential $credentials

Import-PSSession $session -DisableNameChecking

Write-Host "<prtg>"
foreach ($mbx in Get-Mailbox) 
{
    #$name = (Get-MailboxStatistics $mbx.Identity).DisplayName
    $name = $mbx.PrimarySMTPAddress
    $used = (Get-MailboxStatistics $mbx.Identity).TotalItemSize
    Write-Host "<result>" "<channel>$name</channel>" "<value>$used</value>" "<unit>Custom</unit>" "<CustomUnit>MB</CustomUnit>" "<VolumeSize>MegaByte</VolumeSize>" "<float>1</float>" "</result>"
}
Write-Host "</prtg>"
Write-Host 0:OK
Exit 0

The timeout being set to 300 seconds and the scanning interval to 4 hours. It times out with the error code PE018 every time.

The script runs as expected using the Powershell console

exchange pe018 powershell prtg remote timeout

Created on Apr 16, 2013 8:48:31 AM

Last change on Apr 16, 2013 9:22:39 AM by  Konstantin Wolff [Paessler Support]



5 Replies

Votes:

0

Hi,
may you activate the the debug option of the sensor and post the result?
Therefore, on tab Settings of the sensor please set option Result Handling to Write Result to Disk. Then scan the sensor once manually via Scan Now.
This will create a file called Result of Sensor XXXX.txt in the Logs (Sensors) subdirectory of your PRTG Data Directory.
Best regards

Created on Apr 16, 2013 9:29:54 AM by  Konstantin Wolff [Paessler Support]



Votes:

0

Yes, I have just done so, and I'm sorry for the late answer. Was swarmed yesterday ;-)

Here is the result:

ModuleType Name ExportedCommands ---------- ---- ---------------- Script tmp_c60f8aec-971c-4a7e... {Get-IRMConfiguration, New-MailUser, En... <prtg> <result> <channel>uu-lillebaelt.dk</channel> <value>17761284946</value> <unit>Custom</unit> <CustomUnit>MB</CustomUnit> <VolumeSize>MegaByte</VolumeSize> <float>1</float> </result> </prtg> 0:200:Everything OK

Created on Apr 17, 2013 6:54:07 AM



Votes:

0

As an edition to my previous reply, the problem has changed a bit, it is now returning with error code PE132, the format is not well formed.

I've come to the conclusion that it is this part of the response that is giving me trouble:

ModuleType Name ExportedCommands ---------- ---- ---------------- Script tmp_c60f8aec-971c-4a7e... {Get-IRMConfiguration, New-MailUser, En...

But sadly I have no idea how to remove that bit in a Powershell script.

Furthermore, is it necessary to output 0:200:Everything OK?

Created on Apr 17, 2013 6:58:23 AM



Votes:

1

To suppress the first three lines, the output of the import-PSSession command has to be piped to null. Please adjust the according line to:

Import-PSSession $Session -DisableNameChecking | out-null

Additional, you are returning two types of return values.

<prtg>
    <result>
        <channel>uu-lillebaelt.dk</channel>
        <value>17761284946</value>
        <unit>Custom</unit>
        <CustomUnit>MB</CustomUnit>
        <VolumeSize>MegaByte</VolumeSize>
        <float>1</float>
    </result>
</prtg>

This would be the output needed for the EXE/Script Advanced Sensor but this output

0:200:Everything OK

Would be for the EXE/Script Sensor. So depending on the sensor type you are using you will have to adjust the output of the script. You cannot return both types of output.
When you have adjusted your script the values should be picked up by PRTG correctly.

Created on Apr 17, 2013 9:31:10 AM by  Konstantin Wolff [Paessler Support]



Votes:

0

Everything works now, thank you very much for you assistance :-)

Created on Apr 17, 2013 11:02:23 AM




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.