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!"
}
Stelly
  • 27
  • 1
  • 4

1 Answers1

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.

vonPryz
  • 22,996
  • 7
  • 54
  • 65
  • Thanks! I get what your saying now and totally see where I went wrong! Amazing and thank you :) – Stelly Jul 12 '17 at 08:09