I'm getting a malformed XML data on powershell.

This is literally all the powershell script is.

"<prtg>"
    "<result>"
    "<channel>dats</channel>"
    "<value>1</value>"
    "</result>"
"</prtg>"

Can someone please explain to me what I'm doing wrong?

Running the data through an XML validator says all is good. Powershell ISE says all is good, and the data looks like it's suppose to. I've also tried write-host and write-output in various options

Powershell on the system is version 2. PRTG is 18.4.46.1754


Article Comments

Hello Matt,

Thank you very much for your contact.

First things first, are you able to update the used Powershell version 2 to one more up to date, for instance by installing the Windows Windows Management Framework 5.1?

Best regards,
Sebastian


Jan, 2019 - Permalink

Here is what I normally implement in all my PowerShell scripts to generate output:

$XML = "fill this with e.g. your XML code above or what ever your script should output"

Function WriteXmlToScreen ([xml]$xml) #just to make it clean XML code...
{
    $StringWriter = New-Object System.IO.StringWriter;
    $XmlWriter = New-Object System.Xml.XmlTextWriter $StringWriter;
    $XmlWriter.Formatting = "indented";
    $xml.WriteTo($XmlWriter);
    $XmlWriter.Flush();
    $StringWriter.Flush();
    Write-Output $StringWriter.ToString();
}
WriteXmlToScreen "$XML"

This will give you a 100% compatible XML response. What confused me most are all you text-marks in your example, looks odd to me.

Further - this is not a CUSTOM EXE sensor you created there, this is a advanced EXE sensor.

Your output is XML and PRTG might hick up on that, cause I think the regular EXE sensor can't process that (not sure, though, it's a LONG LONG time since I created a regular EXE sensor).

Hope this helps.

Regards

Florian Rossmark

https://www.it-admins.com|www.it-admins.com]]


Jan, 2019 - Permalink

Did you already try adding the <Text> node like:

"<prtg>"
    "<result>"
    "<channel>dats</channel>"
    "<value>1</value>"
    "</result>"
    "<Text>Ok</Text>"
"</prtg>"

Sensors | Multi Channel Sensors | Tools | Notifications

Kind regards,

[[http://prtgtoolsfamily.com]] PRTGToolsFamily


Jan, 2019 - Permalink