title: Test password has special character in powershell script
body: <p>I am trying to build a script that checks that the password has letters and numbers and special characters. This is what I have so far:</p>
  
  <pre><code> Write-Output " Enter db Password - DO NOT Use spaces - " 
   Write-Output " No part of the username can be contained in the password"
  
    do {$pdb=read-host " Must have 8 characters include at least 1 number &amp; 1 special character i.e. help@menow1"
  
     $string = $pdb
     $pat = "^[a-zA-Z0-9\s]+$"
     $special = [regex]"[^a-zA-Z0-9]"
     }
  
    while (!$pdb -or 
  
        !($pdb.length -ge 8) -or
  
        ($pdb.Contains($pat)) -or 
  
        ($pdb.Contains($special))
  
        ) 
  </code></pre>
  
  <p>It does most of what I want. If I input as the password cat and press enter it prompts again for the password to be entered. If I put in cats1234, this passes and the script ends. What I want for it to prompt again and only pass if I put in cats1234$.</p>
  
  <p>Thanks!</p>