title: Use encrypted password for Plink/PuTTY
body: <p>I would like to encrypt a password in PowerShell and use it with <code>plink</code> and <code>putty</code>.</p>
  <p>Yes, I know that it expects only cleartext password (<a href="https://stackoverflow.com/q/14822083/">Password encryption using SecureString for plink.exe command</a>).</p>
  <p>No, I will not use generated keys because we don't support it.</p>
  <p>My questions:</p>
  <ol>
  <li>Any suggestions how can I use encrypted password for <code>-pw</code> flag in <code>putty</code> or <code>plink</code></li>
  <li>Can I generate specific string as key? I mean taking current cleartext password and convert it to a key, then using it as <code>-i</code> instead of <code>-pw</code></li>
  </ol>
  <p>My <code>securePass.ps1</code> code:</p>
  <pre><code>$password = read-host -prompt &quot;Enter your Password&quot; 
  write-host &quot;$password is password&quot; 
  $secure = ConvertTo-SecureString $password -force -asPlainText 
  $bytes = ConvertFrom-SecureString $secure 
  $bytes | out-file C:\encrypted_password1.txt
  </code></pre>
  <p>In main:</p>
  <pre><code>$securePass = Get-Content C:\encrypted_password1.txt
  $pass = $securePass | ConvertTo-SecureString
  plink -batch -ssh $defUser@$srv -pw $pass
  putty -ssh $defUser@$srv -pw $pass
  </code></pre>