Hi,

I made a simple script to show sensor channel in PRTG. It takes value (one number - it's change in file from 1-100) from TXT file and shows in PRTG. But I have a problem beacuse PRTG shows "0" in result.

SCRIPT:

$value = Get-Content .\TXT_File.txt
Write-Host "<prtg>"  
   "<result>"
        "<channel>Channel Name</channel>"
        "<value>$value</value>"
		"<mode>Absolute</mode>"
        "<float>0</float>"
    "</result>"
        "<text>$value</text>"
"</prtg>"

When I add EXE/Script Advanced powershell script it shows "0" in PRTG sensor channel.

So I try to convert string to integer

$value = Get-Content .\TXT_file.txt
$value = $value -as [int] 
Write-Host "<prtg>"  
   "<result>"
        "<channel>Channel Name</channel>"
        "<value>$value</value>"
		"<mode>Absolute</mode>"
        "<float>0</float>"
    "</result>"
        "<text>$value</text>"
"</prtg>"

The same result - PRTG show "0".

When I manually add value everyting works ok:

$value = 99
Write-Host "<prtg>"  
   "<result>"
        "<channel>Channel Name</channel>"
        "<value>$value</value>"
		"<mode>Absolute</mode>"
        "<float>0</float>"
    "</result>"
        "<text>$value</text>"
"</prtg>"

What I do wrong?

Thank You.


Article Comments

Hello,

I tried to recreate the issue. With this script it was working when I add one number to my .txt file.

$value = Get-Content -Path "C:\Path Example\Test.txt" $value = $value -as [int] Write-Host "<prtg>" "<result>" "<channel>Channel Name</channel>" "<value>$value</value>" "<mode>Absolute</mode>" "<float>0</float>" "</result>" "<text>$value</text>" "</prtg>"


Kind regards

Felix Wiesneth - Team Tech Support


Apr, 2020 - Permalink

Felix - thank You - You're right! :) That was my error - no full path to file. Now everything works fine.


Apr, 2020 - Permalink