PowerShell: Encrypt and decrypt a password to plain text

Suppose I am connecting to a system that does not understand secure string? I am connecting to a non-Msft system and it wants the password in plain text.

Solution

Encrypt and store the data in text using this ——– Read-Host -Prompt “Mypassword” -AsSecureString | ConvertFrom-SecureString | Out-File “D:\Portal\MySnowpwd.key”

In your program add these 2 lines to get the password in plain text

$Getpass = Get-content “D:\Portal\MySnowpwd.key” | ConvertTo-SecureString

$pass = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Getpass))

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s