Hi, I have a pretty straight forward Powershell script:
$variable = do something If ($variable -eq "Something 1"){ write-host "0:All Good" exit 0} Elseif ($variable -eq "Something 2"){ write-host "1:Not so good" exit 1} Else {exit 1}
If I run such a script directly on a server, the if/elseif's are processed correctly.
If I run this same script as a Custom EXE sensor, I never seem to get past the first IF statement.
Any ideas?
Article Comments
No errors. If the $variable equals something that should trigger the ELSEIF statement, PRTG persists on returning "All is good". The sensor is green and responding like nothing is wrong.
If I run it directly on the server being monitored, powershell correctly reports "Not so good" indicating that the logic of the script is correct.
Aug, 2015 - Permalink
Nothing but -hostname %host. Here's the script:
param ( [string]$hostname ) $LogonMode = Invoke-Command { Add-PSSnapin Citrix.XenApp.Commands; $(Get-XAServer -ServerName $hostname).LogonMode } -ComputerName $hostname | Select -Expand Value If ($LogonMode -eq "AllowLogOns") {write-host "0:All Logons Allowed" exit 0} ElseIf ($LogonMode -eq "ProhibitNewLogOnsUntilRestart") {write-host "1:Prohibit Logons Until Server Restart" exit 1} ElseIf ($LogonMode -eq "ProhibitNewLogOns") {write-host "2:Prohibit Logons Only" exit 1} ElseIf ($LogonMode -eq "ProhibitLogOns") {write-host "3:Prohibit Logons and Reconnections" exit 1} Else {exit 1}
It's simply identifying the logon mode of a XenApp server. If I run this directly on a XenApp server, the ELSEIF's are processed correctly according to its actual logon mode.
When prtg runs it, it constantly stops at "0:All Logons Allowed".
Aug, 2015 - Permalink
Hi Stan,
Can you try the following: http://pastebin.com/raw.php?i=spaxSS4e It works, when I set the logonmode manually to the corresponding strings. Also, looks a bit better than the if statements :)
Aug, 2015 - Permalink
It works...but something doesn't like the $hostname variable.
If I specify "-hostname %host" in the parameters field of the sensor, it always returns back 'Allow logons'.
If I edit the .ps1 and replace $hostname with the name of the actual server, the sensor works as expected.
Aug, 2015 - Permalink
Call it "server1".
I have some other sensors which use the invoke-command to run other XenApp commands, these too also use the $hostname variable in the script. I pass it via the same "-hostname %host" parameter in the sensor without error.
Aug, 2015 - Permalink
Hm...really not sure what's causing this - What's the content of $LogonMode - is it possible that its a PSObject and you'll need to access a property of it, not the object itself? That should explain, why it's stuck on the first...
Aug, 2015 - Permalink
What errors do you get? Or are you stuck with All is good?
Aug, 2015 - Permalink