In my current script, I have defined 2 variables at the top of the script:
$errorcode = 0
$time_errorcode = 0
The rest of the script consists of 2 foreach loops for each one of these variables. Basically if the loop succeeds, then the variable stays at 0 and if the loop fails, the variable changes to 1. I am trying to figure out now how I can properly "exit" the script with the exit code that I need based on whether or not these forloops succeeded or failed. The way I am doing is as follows:
if ($errorcode = 1 -and time_errorcode = 1){exit 0"}
if ($errorcode = 1 -and $time_errorcode = 0){exit 1"}
if ($errorcode = 0 -and $time_errorcode = 1){exit 2"}
The problem that I'm running in to is that PowerShell is telling me that this snippet: if ($errorcode = 0 -and $time_errorcode = 1)
is invalid. The error that I'm getting is:
The input to an assignment operator must be an object that is able to accept assignments, such as a variable or a property.
I guess I don't know how to properly compare these 2 variables together to get the exit code that I desire. What is the best procedure to do this?