0

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?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
RaptorPete
  • 139
  • 12
  • 2
    Use `-eq` instead of `=`. `if (($errorcode -eq 1) -and ($time_errorcode -eq 1))` – lit Oct 12 '18 at 16:48
  • 1
    As @lit said, use the -eq operator instead of =. In PowerShell, the equal sign is an assignment operator while the -eq is used strictly for equality. You're re-assigning your variables to those values in your statement. – Peter Kay Oct 12 '18 at 18:49

0 Answers0