 <p><a href="http://stackoverflow.com/a/38012152/1163423">sodawillow provided a valid answer</a>. Howevery, you can simplify this using <code>-notin</code>:</p> <pre><code>if ($SER -notin 'Y', 'N') { Write-Host "ERROR: Wrong value for services restart" -ForegroundColor Red } </code></pre>