I second that. When I saw Rick had responded, it put a smile on my face.
Loren, you are asking some interesting questions. Love to see it.
Original Message:
Sent: May 20, 2025 08:33 AM
From: Lucy Zhang
Subject: PowerShell script exit not recognized by ESP NT_JOB
Hi Rick,
So nice to "see" you again.
Thank you for your input as always,
Lucy
Original Message:
Sent: May 19, 2025 07:56 PM
From: Rick Romanowski
Subject: PowerShell script exit not recognized by ESP NT_JOB
I added a Function to the PowerShell script, then called it before exiting the script.
Function
#-----------------------------------------------------------------------------------#
# Functions ExitWithCode #
#-----------------------------------------------------------------------------------#
function ExitWithCode
{
param
(
$exitcode
)
$host.SetShouldExit($exitcode)
exit
}
Program Excerpt
#####################################################################################
# #
# Main Program #
# #
#####################################################################################
$global:ExitStatus = 0
.
.
.
ExitWithCode -exitcode $ExitStatus
Original Message:
Sent: May 19, 2025 02:12 PM
From: Loren Watts
Subject: PowerShell script exit not recognized by ESP NT_JOB
Is there a way to have ESP recognize my coded exit number in a PowerShell script?
I'm trying to have an ESP NT_JOB run a script on a Windows 2019 server and act upon the exit code in my PowerShell script.
The NT_JOB seems to only see the end of the PowerShell script as a 0 or 1
In this primitive example I end the script with exit 777.
The ESP job executing the script sees Completion Code CC 1 rather than 777
CMDNAME powershell
ARGS e:\Scripts\return-code-to-for-esp-use.ps1
Example PowerShell script
Write-Output "Going to exit with 777";
exit 777
^^^^^^^^^^^^^^^
Ran from PowerShell on the server
PS C:\Users\Loren> E:\Scripts\return-code-to-for-esp-use.ps1
Going to exit with 777
PS C:\Users\Loren> $?
True
PS C:\Users\C3829B> $LASTEXITCODE
777
PS C:\Users\C3829B>
------------------------------
Loren Watts
Cigna Healthcare
------------------------------