When execute this script the text is not displayed. Instead PRTG shows "Ung?ltige Eingabe".

How do i show the Exchange Version?

<#
===================================================================================
Paessler PRTG Sensor to check Exchange Server Version
===================================================================================
Autor:        Stefan Redlin
Script:       CheckExchangeVersion.ps1
Version:      1.0
Date:         26.04.2019
Environment:  Windows Server 2016/Exchange2016
Scriptpath:   C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML
Scripttype:   EXE/Script Advanced
#>
$result = Invoke-Command -ComputerName EX-01 {$query = Get-Command Exsetup.exe | select Version
$query}


$Version = $result.version.ToString()
$output= switch ($Version){

15.1.225.16 {"Exchange Server 2016 Preview"}
15.1.225.42 {"Exchange Server 2016 RTM"}
15.1.396.30 {"Exchange Server 2016 Cumulative Update 1 (CU1)"}
15.1.466.34 {"Exchange Server 2016 Cumulative Update 2 (CU2)"}
15.1.544.27	{"Exchange Server 2016 Cumulative Update 3 (CU3)"}
15.1.669.32 {"Exchange Server 2016 Cumulative Update 4 (CU4)"}
15.1.845.34 {"Exchange Server 2016 Cumulative Update 5 (CU5)"}
15.1.1034.26 {"Exchange Server 2016 Cumulative Update 6 CU6"}
15.1.1261.35 {"Exchange Server 2016 Cumulative Update 7 (CU7)"}
15.1.1415.2 {"Exchange Server 2016 Cumulative Update 8 (CU8)"}
15.1.1466.3	 {"Exchange Server 2016 Cumulative Update 9 (CU9)"}
15.1.1531.3 {"Exchange Server 2016 Cumulative Update 10 (CU10)"}
15.1.1591.01 {"Exchange Server 2016 Cumulative Update 11 (CU11)"}
15.1.1713.5 {"Exchange Server 2016 Cumulative Update 12 (CU12)"}
default {"Ungültige Eingabe"}
}


Write-Host @"
<prtg>
<result>
<channel>Exchange Version</channel>
<value>0</value>
</result>
<text>$output</text>
</prtg>
"@

Output looks like

<prtg>
<result>
<channel>Exchange Version</channel>
<value>0</value>
</result>
<text>Exchange Server 2016 Cumulative Update 6 CU6</text>
</prtg>

Article Comments

SRedlin,

Would it be possible for you to upload an image of the sensor, and link it here?

I need to see what error message the sensor is showing.

Benjamin Day
Paessler Support


Apr, 2019 - Permalink

Hey Benjamin, here is the link to the image https://ibb.co/f8rW2BB

Like i said in my first post i recieve "Ung?ltige Eingabe" instead of the Exchange Version in PRTG GUI


Apr, 2019 - Permalink

SRedin,

In your script you have the entry for "default {"Ungültige Eingabe"}" in your switch table.

This would lead me to think the value returned is not one within the scope you've set.

Can you have your script output the version number for testing?

Benjamin Day
Paessler Support


Apr, 2019 - Permalink

When i uncomment the line "default {"Ungültige Eingabe"}" the sensor output changes to OK.

In Powershell ISE i got Exchange Server 2016 Cumulative Update 6 CU6 as output for the variable $output. So i think my value for the version seems to be correct.

<prtg> <result> <channel>Exchange Version</channel> <value>0</value> </result> <text>Exchange Server 2016 Cumulative Update 6 CU6</text> </prtg>


Apr, 2019 - Permalink

SRedin,

So what does the Message field in the sensor say now?

Benjamin Day
Paessler Support


Apr, 2019 - Permalink

When i uncomment the line "default {"Ungültige Eingabe"}" the sensor output changes to OK. https://ibb.co/VQsdPSS


Apr, 2019 - Permalink

Hello, as script returns "ungültige Eingabe" even if the actual call fails. I'd "enable" logging within the script by writing the content of $result perhaps into its own logfile (or even adding this to the output-line to PRTG).

Write-Host @"
<prtg>
<result>
<channel>Exchange Version</channel>
<value>0</value>
</result>
<text>$result</text>
</prtg>
"@

This should show any eventual error messages then.


Apr, 2019 - Permalink

Changed the script a little bit, for troubleshooting proposes.

<#
===================================================================================
Paessler PRTG Sensor to check Exchange Server Version
===================================================================================
Autor:        Stefan Redlin
Script:       CheckExchangeVersionV2.ps1
Version:      1.0
Date:         01.05.2019
Environment:  Windows Server 2016/Exchange2016
Scriptpath:   C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML
Scripttype:   EXE/Script Advanced
$result = Invoke-Command -ComputerName EX-01 {$query = Get-Command Exsetup.exe | select Version
$query}
#>


$result = Invoke-Command -ComputerName EX-01 -ScriptBlock {$query = Get-Command Exsetup.exe | select Version
$query}

$Version = $result.version.ToString()
$Version|Out-file C:\temp\Version.txt
$content = Get-Content C:\temp\Version.txt
#region: XML Output for PRTG
Write-Host "<prtg>" 
if($Version -eq "15.1.225.16"){$Count=1}else{$count=0}
Write-Host "<result>"
               "<channel>Exchange Server 2016 Preview</channel>"
               "<value>$Count</value>"
               "<text>Exchange Server 2016 Preview</text>"
               "</result>"
if($Version -eq "15.1.225.42"){$Count=1}else{$count=0}
Write-Host "<result>"
               "<channel>Exchange Server 2016 RTM</channel>"
               "<value>$Count</value>"
               "<text>Exchange Server 2016 RTM</text>"
               "</result>"
if($Version -eq "15.1.396.30"){$Count=1}else{$count=0}
Write-Host "<result>"
               "<channel>Exchange Server 2016 CU1</channel>"
               "<value>$Count</value>"
               "<text>Exchange Server 2016 CU1</text>"
               "</result>"
if($Version -eq "15.1.466.34"){$Count=1}else{$count=0}
Write-Host "<result>"
               "<channel>Exchange Server 2016 CU2</channel>"
               "<value>$Count</value>"
               "<text>Exchange Server 2016 CU2</text>"
               "</result>"
if($Version -eq "15.1.544.27"){$Count=1}else{$count=0}
Write-Host "<result>"
               "<channel>Exchange Server 2016 CU3</channel>"
               "<value>$Count</value>"
               "<text>Exchange Server 2016 CU3</text>"
               "</result>"
if($Version -eq "15.1.669.32"){$Count=1}else{$count=0}
Write-Host "<result>"
               "<channel>Exchange Server 2016 CU4</channel>"
               "<value>$Count</value>"
               "<text>Exchange Server 2016 CU4</text>"
               "</result>"
if($Version -eq "15.1.845.34"){$Count=1}else{$count=0}
Write-Host "<result>"
               "<channel>Exchange Server 2016 CU5</channel>"
               "<value>$Count</value>"
               "<text>Exchange Server 2016 CU5</text>"
               "</result>"
if($content -eq "15.1.1034.26"){[string]$Count='1'}else{[string]$count='0'}
Write-Host "<result>"
               "<channel>Exchange Server 2016 CU6</channel>"
               "<value>$Count</value>"
               "<text>Exchange Server 2016 CU6</text>"
               "</result>"
Write-Host "</prtg>" 
#endregion

##########################################################################

If i run the script in Powershell or ISE, a textfile for debugging is been written, if i open the file i can see the value 15.1.1034.26 which indicates Exchange Server 2016 CU6. When PRTG EXE/Script Advanced Sensor is executing the script the file is empty.

Why does PRTG have this behavior and how can i fix it?

Second problem, when i just import the file which includes the version number with get-content and run the sensor the if else statement also do not work like expected.

ISE and Powershell Output for Channel Exchange 2016 CU6

<result>
<channel>Exchange Server 2016 CU6</channel>
<value>1</value>
<text>Exchange Server 2016 CU6</text>
</result>

May, 2019 - Permalink

If the script doesn't write into the file when executed by PRTG, it could mean, it doesn't even get to the part when executed by PRTG (consider permissions when you run the script vs. when PRTG runs it as LOCAL SYSTEM). Also, a "<text>" - property inside the channel result doesn't work. There can only be one <text> outside of the channel results in the XML. You have to change it from:

<result>
<channel>Exchange Server 2016 CU6</channel>
<value>1</value>
<text>Exchange Server 2016 CU6</text>
</result>

to:

<result>
<channel>Exchange Server 2016 CU6</channel>
<value>1</value>
</result>
<text>Exchange Server 2016 CU6</text>

May, 2019 - Permalink