Save-Credentials
Saves credentials encrypted
param([string]$targetFile = "~\my.credentials")
try {
Write-Host "Enter username and password, please." -foreground red
$cred = Get-Credential
$cred.Password | ConvertFrom-SecureString | Set-Content "$targetFile"
"? Your credentials have been saved to $targetFile (encrypted)."
exit 0 # success
} catch {
"?? ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
exit 1
}Specifies the target file ("~\my.credentials" by default)