I’m facing a strange problem.
I have several scripts that use a credential saved using cmdlet Export-cliXML, and i get it using Import-cliXML.
They successfully run during all month of june.
Last monday (1st july) the scripts failed with error “Key not valid for use in specified state” (regenerating the XML file fixed the problem).
To my knowledge nothing changed (the server is the same, the account used to encrypt/decrypt did not change), did someone experienced such an error ?
I’ve read that this method uses “windows data protection API”, is it possible something could break it ?
here is the source code (standard for this use case) :
Encrypt
$svcAccount="fake value"
$credsPath="d:datafilesfile.xml"
$askForPassword = Read-Host -Prompt "Enter password" -AsSecureString
$credential = New-Object PSCredential -ArgumentList $svcAccount, $askForPassword
$credential | Export-Clixml -Path $credsPath
Decrypt
$credsPath="d:datafilesfile.xml"
$credential = Import-Clixml -Path $credsPath
Olivier Gouret is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.