vendredi 27 février 2015

ConvertTo-SecureString - Key not valid for use in specified state After Reboot

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?


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.


I create the password file via:



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."


I retrieve the password from the file like so:



$FTPPassword = Get-Content $FTPPasswordFilePath
$script:FTPCredObj = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $FTPUserName,($FTPPassword | ConvertTo-SecureString)

Aucun commentaire:

Enregistrer un commentaire