save PSCredential in the file
<p>I know I can save password to the file:</p>

<pre><code>Read-Host "Enter Password" -AsSecureString |  ConvertFrom-SecureString | Out-File $passwordfile
</code></pre>

<p>and read it from file:</p>

<pre><code>$secpasswd = (Get-Content $passwordfile | ConvertTo-SecureString)
</code></pre>

<p>and then create PSCredential object:</p>

<pre><code>$credential = New-Object System.Management.Automation.PSCredential($user, $secpasswd)
</code></pre>

<p>But can I save $credential in the file, so username and his password were kept together?</p>