0

I'm having issue with this while loop. Even when the status is returned as online its still stuck in the while loop... any ideas would be amazing :)

$instance = "(opsworks instance id)"

$status = (Get-OPSInstance -InstanceId $instance  -Region eu-west-1).Status.Trim()
Write-Host "Initial:$status"

while($status -ne 'online' -or $status -ne 'start_failed')
{
  $status = (Get-OPSInstance -InstanceId $instance  -Region eu-west-1).Status.Trim()
  Write-Host "Next:$status!"
}
1
  • Change -or to -and; when it is 'online' it is also 'not start_failed' so the loop still loops. Commented Jul 12, 2017 at 7:59

1 Answer 1

2

This is a basic boolean algebra. It happens as online is not equal to start_failed. The -or operator will check both sides of the expression and will return true incase of either matches.

Condition

($status -ne 'online' -and $status -ne 'start_failed')

will be evaluated as false iff $status is neither online nor start_failed.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I get what your saying now and totally see where I went wrong! Amazing and thank you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.