Page 1 of 1

ps1 plugin not returning proper exit code

Posted: Tue Sep 21, 2021 12:07 pm
by BanditBBS
So, I converted all my Windows servers over to NCPA, YAY!! I wrote a new plugin using powershell and this is the bottom of the code:

Code: Select all

if ( ( $days -ge $threshold ) ) {
    $returnString = "CRITICAL: " + $days + " since last update"
    $returnState = $returnStateCritical
} else {
	$returnString = "OK: " + $days + " since last update"
    $returnState = $returnStateOK
}

Write-Host $returnString
exit $returnState
No matter what happens though, NCPA is saying it is OK. Example here:
Screenshot 2021-09-21 130624.jpg
I even went on this host, modified the .ps1 to "exit 2" and NCPA still shows the above screenshot.

My Config for ps1 files in NCPA is the default settings. Any idea why this isn't returning the exit code as desired?

Re: ps1 plugin not returning proper exit code

Posted: Tue Sep 21, 2021 5:39 pm
by BanditBBS
After further testing, I believe I narrowed it down to just the remaining 2008 and 2008 R2 hosts we have. 2012 and higher seem to be exiting with the correct exit code!

Re: ps1 plugin not returning proper exit code

Posted: Wed Sep 22, 2021 12:28 pm
by ssax
I just labbed it up on 2008R2 with NCPA 2.3.1 and it's working properly (no service restarted needed when changing the plugin). What version of NCPA is the system running?

Re: ps1 plugin not returning proper exit code

Posted: Wed Sep 22, 2021 12:41 pm
by BanditBBS
2.3.1 on them all. Wonder what on earth could be making it only exit with 0 on my 2008 R2 boxes.

Re: ps1 plugin not returning proper exit code

Posted: Wed Sep 22, 2021 1:09 pm
by BanditBBS
I found the issue. This script was one I found online, first line was this:

Code: Select all

[CmdletBinding()]
I commented it out and it now works fine on the 2008 hosts. Crazy, but thanks for making me look deeper!

Re: ps1 plugin not returning proper exit code

Posted: Thu Sep 23, 2021 11:14 am
by ssax
Interesting, thanks for posting the update! Really not sure why that would cause it to fail.