none
PowerShell text to secure string without using read-host RRS feed

  • Question

  • I've made several form objects with powershell and I want to have one of its textboxes containt the password data so I can then place it to the registry key. The thing is I would like to keep it there as secure text.

    $Pass = (Read-Host 'specify password' -asSecureString | ConvertFrom-SecureString)
    $RegPath = 'HKCU:\Software\MyApp'
    New-Item -Path $RegPath -Name "Password" -Value "Default Value" -Force
    New-ItemProperty $RegPath -Name "Password"-PropertyType "String" -Value $CreatePass -Force
    $PassPath = (Get-ItemProperty -Path $Registry -Name Password).Password
    $LocAdmCred = domain\user
    $CredentialsSet = New-Object System.Management.Automation.PSCredential -ArgumentList @($LocAdmCred,(ConvertTo-SecureString -String $PassPath))
    What I want to set my $Pass variable to textbox.text value as secure string.

    Friday, July 11, 2014 8:12 AM

Answers

  • Alright. Seems like I figured out.

    $a = ConvertTo-SecureString -String 'TESTTEXT' -AsPlainText -Force
    $a | ConvertFrom-SecureString

    This will return secure string as plain text just like I wanted to.

    In case anyone else needs stuff like that:

    http://social.technet.microsoft.com/wiki/contents/articles/4546.working-with-passwords-secure-strings-and-credentials-in-windows-powershell.aspx

    • Marked as answer by KirillPashkov Friday, July 11, 2014 8:28 AM
    Friday, July 11, 2014 8:28 AM

All replies

  • Alright. Seems like I figured out.

    $a = ConvertTo-SecureString -String 'TESTTEXT' -AsPlainText -Force
    $a | ConvertFrom-SecureString

    This will return secure string as plain text just like I wanted to.

    In case anyone else needs stuff like that:

    http://social.technet.microsoft.com/wiki/contents/articles/4546.working-with-passwords-secure-strings-and-credentials-in-windows-powershell.aspx

    • Marked as answer by KirillPashkov Friday, July 11, 2014 8:28 AM
    Friday, July 11, 2014 8:28 AM
  • If you are looking for a one-liner

    $a = "thisisastring" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString

    Thursday, June 1, 2017 7:24 PM