title: ConvertTo-SecureString - Key not valid for use in specified state After Reboot
body: <p>I have a Powershell script that's been running from months using a password stored as a secure string in a file. When I went to run the script today I started receiving the "Key not valid for use in specified state". The script is invoked by a scheduled task run by an active directory domain account. The account didn't change, and the only event I'm aware of was a server reboot. What could cause this issue to happen?</p>
  
  <p>Converting my data back into a secure string again resolved the issue, but I'm puzzled as to why it happened in the first place.</p>
  
  <p>I create the password file via: </p>
  
  <pre><code>Write-Host "Please enter the filename where you'd like to store the password:"
  $passwordFile = Read-Host
  Write-Host "Please enter the ftp password and press enter:"
  read-host -AsSecureString | ConvertFrom-SecureString | Out-File $passwordFile
  Write-Host "Your Password File ($passwordFile) has been created."
  </code></pre>
  
  <p>I retrieve the password from the file like so:</p>
  
  <pre><code>$FTPPassword = Get-Content $FTPPasswordFilePath
  $script:FTPCredObj = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $FTPUserName,($FTPPassword | ConvertTo-SecureString)
  </code></pre>
  
  <p>I did notice errors in the event log pertaining to the user profile:</p>
  
  <p>"Windows cannot find the local profile and is logging you on with a temporary profile. Changes you make to this profile will be lost when you log off."</p>
  
  <p>I did RDP in as the task user to update the file containing the secure string, and I didn't notice any profile errors after that.</p>