title: PowerShell: how to check how many digits were entered for user pin
body: <p>I'm trying to write a powershell script that asks for a user to input a 4 digit pin, and if the number is not equal to 4, a warning is issued.</p>
  <p>Here's what I have but it doesn't seem to work...</p>
  <pre class="lang-sh prettyprint-override"><code>[int]$userPin = read-host 'type in your user pin'
  if ($userPin.length -ne 4) {
    write-host &quot;Error, Pin must be 4 numbers&quot;
  }
  </code></pre>
  <p>this code writes the error message no matter what...
  Any help is appreciated!
  THANKS!</p>