Storing credentials in encrypted form
suggest changeThe first file must be the output of ConvertFrom-SecureString with no key. That uses Windows DPAPI, so the same user on the same computer can decrypt it. A plaintext password in the file will not convert.
$username = "user1@domain.com"
$pwdTxt = Get-Content "C:\temp\Stored_Password.txt"
$securePwd = $pwdTxt | ConvertTo-SecureString
$credObject = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $securePwd
# $credObject holds the credential. Pass it to -Credential.
## Import Password with AES
$username = "user1@domain.com"
$AESKey = Get-Content $AESKeyFilePath
$pwdTxt = Get-Content $SecurePwdFilePath
$securePwd = $pwdTxt | ConvertTo-SecureString -Key $AESKey
$credObject = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $securePwd
# $AESKeyFilePath and $SecurePwdFilePath must already be set.
# $credObject holds the credential encrypted with that AES key.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents