PowerShell Script Password Encryption
I'm posting this because it took me two days to figure out. I needed a script I could run in a room full of backseat drivers. I couldn't hardcode the username and password into the script, and I didn't want to use Read-Host with people looking over my shoulder. This is what I came up with:
Works like a charm. I get a username/password popup from
Hope this helps someone.
$Creds = Get-Credential $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Sftp HostName = "sftp.url.com" UserName = $Creds.UserName Password = (ConvertFrom-SecureToPlain -SecurePassword $Creds.Password) SshHostKeyFingerprint = "redacted gobbledegook" }
Works like a charm. I get a username/password popup from
Get-Credential
where the password shows as *****, and the (ConvertFrom-SecureToPlain -SecurePassword $Creds.Password)
converts the password into something the SFTP server understands.
Hope this helps someone.