![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| | Vista - read-host -assecurestring problem |
![]() |
| |
| 06-05-2008 | #1 |
| | read-host -assecurestring problem I want to be able to type in a password and have it masked with ****, but I need it to be in plain-text in the script I'm using. So I tried the following: $SecurePassword = read-host -AsSecureString "Type in your new password" $PlainPassword = ConvertFrom-SecureString $SecurePassword write-host "Plain Text Password = " $PlainPassword When I run this, instead of getting a plain-text version of the password, I get a long string of numerals. Granted I'll not simply just post the password to the user, but for the sake of example the above snippet shows my point and problem. The problem I have with using read-host without the -assecurestring is two-fold: 1. Anyone can see what you type in 2. What you type into read-host is stored in the command history, so you can just "up-arrow" and see what was last typed into read-host. I want to prevent people from looking over one's shoulder and not have the value stored in the command history. So what do I need to do in order for powershell to use read-host -assecurestring and yet be able to use the plain-text value of the password later in the script. |
My System Specs![]() |
| 06-05-2008 | #2 |
| | Re: read-host -assecurestring problem On Jun 5, 11:54*am, GodOfLions <GodOfLi...@xxxxxx> wrote: Quote: > I want to be able to type in a password and have it masked with ****, but I > need it to be in plain-text in the script I'm using. So I tried the following: > > $SecurePassword = read-host -AsSecureString "Type in your new password" > $PlainPassword = ConvertFrom-SecureString $SecurePassword > write-host "Plain Text Password = " $PlainPassword > > When I run this, instead of getting a plain-text version of the password, I > get a long string of numerals. Granted I'll not simply just post the password > to the user, but for the sake of example the above snippet shows my point and > problem. > > The problem I have with using read-host without the -assecurestring is > two-fold: > 1. Anyone can see what you type in > 2. What you type into read-host is stored in the command history, so you can > just "up-arrow" and see what was last typed into read-host. > > I want to prevent people from looking over one's shoulder and not have the > value stored in the command history. > > So what do I need to do in order for powershell to use read-host > -assecurestring and yet be able to use the plain-text value of the password > later in the script. SecureString objects are part of the deeper operating system rather than something PowerShell invented, so there are a few hoops to jump through and apologies if I don't explain this but it's a bit hairy. Function ConvertTo-PlainText( [security.securestring]$secure ) { $marshal = [Runtime.InteropServices.Marshal] $marshal::PtrToStringAuto( $marshal::SecureStringToBSTR($secure) ) } usage: ps > $s = read-host -assecurestring "password?" password?: **** ps > convertto-plaintext $s test Hope this helps, - Oisin PowerShell MVP http://www.nivot.org/ |
My System Specs![]() |
![]() |
![]() |
| Thread Tools | |
| |
Similar Threads for: read-host -assecurestring problem
| ||||
| Thread | Forum | |||
| Host File Not Read behind Server | SBS Server | |||
| Can't read physical CD without rebooting host | Virtual Server | |||
| Read-Host values into an Array | PowerShell | |||
| Read-Host issue, won't store to variable when using multiple read-host lines | PowerShell | |||
| Default value for Read-Host | PowerShell | |||