powershellsessionsecurestring

Understanding Powershell SecureStrings


today, I wanted to dig deeply into the concept of SecureString .NET and Powershell, yet I don't think, I am understanding it very well.

If I have a password and convert it to a securestring. Is it saved as I entered it? (Being both encrypted or plain text).

Now if I would pass the password as a part of a PSCredential to a PSSession: what would happen? Does PSSession run ConvertFrom-SecureString on the passed password? But then the password is being encrypted again. How does it know how to pass it to a PSSesion?


Solution

  • I don't fully understand your question but get the jist. This will probably be easier if you think in terms of object types (some explanation). [This link is now dead.]

    "If I have a password and convert it to a securestring. Is it saved as I entered it? (Being both encrypted or plain text)"

    Approach 1
    This creates an encrypted SecureString variable called $SecurePassword. The unencrypted password does not make it to memory.

    $SecurePassword = Read-Host -Prompt "Enter password" -AsSecureString
    

    Approach 2
    This creates an unencrypted String variable $PlainPassword, then a SecureString variable.

    $PlainPassword = Read-Host -Prompt "Enter password"
    $SecurePassword = $PlainPassword | ConvertTo-SecureString -AsPlainText -Force
    

    "Now if I would pass the password as a part of a PSCredential to a PSSession: what would happen?"