Using an Encrypted AES string
Using an encrypted password in a powershell script
The following script uses a variable that has the encrypted password. This string can be read from a separate file which can be more secure. Keeping the Key file and the Encrypted password file separate and controlled by appropriate security and access permissions.
$encPass="76492d1116743f0423413b16050a5345MgB8ADYATwBDADYANQBFA1ADkAZAA5AGMAOAA4AGMAMAA5ADMAZgAwAGYANQA2AGMAZQBmADcAMQBhAGQAMAA5ADEANgBhADUAYwA5ADUAZAA4ADEAOQAzAGQAYQA0ADUAOQAxADMA"
$key = Get-Content "\\PathTo\testkey.aes"
$user = "username"
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, ($encPass | ConvertTo-SecureString -Key $key)