title: Powershell, check that the service is running and if it is not, start it
body: <p>I have created a powershell script that detects if X service is active or not, if not, it starts it. I also wanted to add a parameter in the while to avoid that the script gets stuck and after several attempts (2) it closes the script.</p>
  <p>The script works, it starts the service, but it tries to do the or even though the first statement was true. And not the reason why it does not work:</p>
  <pre><code>$ServiceName = 'MSIREGISTER_MR'
  $arrService = Get-Service -Name $ServiceName
  $conteo = 0
  
   
  
  while (($arrService.Status -ne 'Running') -or ($conteo -ne '2'))
  {
  
   
  
      Start-Service $ServiceName
      write-host $arrService.status
      write-host 'Arrancando el servicio...'
      $conteo = $conteo +1
      Start-Sleep -seconds 5
      $arrService.Refresh()
      if ($arrService.Status -eq 'Running')
      {
          Write-Host 'El servicio esta arrancado'
      }
      else 
      {
          Write-Host 'Fallo al arrancar el servicio'
      }
  
   
  
  }
  </code></pre>