Hey there!
Sometimes you may have a need to encode or encrypt a string. This is usually neccessary for strings like passwords.
Let’s start with creating an encrypted string:
$password = "MostSecureOne123" # Convert password to Secure String $password_SecureString = ConvertTo-SecureString -String $password -AsPlainText -Force # Convert a secure string to an encrypted string $password_EncryptedString = ConvertFrom-SecureString $password_SecureString
Good, this can be now saved or further manipulated.
When you need to decrypt the string, use following:
# Convert from Encrypted string to Secure string $password_SecureString = ConvertTo-SecureString -String $password_EncryptedString # Convert from Secure string to plain text $Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $env:username,$password_SecureString $PlainPassword = $Credentials.GetNetworkCredential().Password # Here it is! $PlainPassword
Let me know whether this was useful to you, or not.
Cheers!
Robot(ICT) guy