title: How to check if the user hits enter with no input in a powershell script?
body: <p>I have a powershell script where I want the user to input a value and the script returns a randomized string for a password.  If they just hit enter when prompted for the length of the password, I want it to be a default of 9 characters.  </p>
  
  <p>How do I handle no input?</p>
  
  <p>I tried something like this, but don't think it is quite right:</p>
  
  <p>Write-Host Enter the password length requirement:</p>
  
  <pre><code>$length = Read-Host
  IF ( $length -eq $NULL) 
      { Do continue on with the value of 9 for the length}
  ELSE
      {Use $length for the rest of the script}
  </code></pre>
  
  <p>The else portion works just fine; however when generating passwords I keep finding myself typing 9 over and over again.  I'd rather just hit enter.  </p>
  
  <p>Any help is greatly appreciated!</p>