Summary of the new feature/enhancement
In order to avoid secrets getting stored in my PSReadLine history, I never paste a secret directly onto the command line as a parameter value. I always use Read-Host -AsSecureString and then paste the secret at the Read-Host prompt. The secret input is masked with * chars. Then I run through this little dance to extract the plain text secret into a variable which honestly, is getting a little tiresome to do (and explain to folks why they need to do this):
PS> $ss = Read-Host -AsSecureString
*******************************
PS> $apiKey = [pscredential]::new('jpgr', $ss).GetNetworkCredential().Password
Then I use the $apiKey variable as the parameter value. Now, yeah, it would be better to use a SecureString but unfortunately, I have to use commands that don't accept a secure string and on top of that, SecureString isn't really secure on any platform except Windows.
What would make life easier in this scenario is this simple addition to Read-Host:
$apiKey = Read-Host -MaskInput
Read-Host already knows how to mask input since it does this when you specify -AsSecureString
Proposed technical implementation details (optional)
Add a new parameter set to Read-Host that adds -MaskInput and is mutually exclusive with -AsSecureString and outputs a System.String object. Now, if you want to require this new parameter to require a -Force parameter to work ala ConvertTo-SecureString 'foo' -AsPlainText -Force, that would be OK. And without the -Force parameter, this would error with a similar error message - The system cannot protect plain text input. To suppress this warning and process the plain text secret, reissue the command specifying the Force parameter..
Summary of the new feature/enhancement
In order to avoid secrets getting stored in my PSReadLine history, I never paste a secret directly onto the command line as a parameter value. I always use
Read-Host -AsSecureStringand then paste the secret at the Read-Host prompt. The secret input is masked with*chars. Then I run through this little dance to extract the plain text secret into a variable which honestly, is getting a little tiresome to do (and explain to folks why they need to do this):Then I use the
$apiKeyvariable as the parameter value. Now, yeah, it would be better to use a SecureString but unfortunately, I have to use commands that don't accept a secure string and on top of that, SecureString isn't really secure on any platform except Windows.What would make life easier in this scenario is this simple addition to
Read-Host:Read-Host already knows how to mask input since it does this when you specify
-AsSecureStringProposed technical implementation details (optional)
Add a new parameter set to Read-Host that adds
-MaskInputand is mutually exclusive with-AsSecureStringand outputs a System.String object. Now, if you want to require this new parameter to require a-Forceparameter to work alaConvertTo-SecureString 'foo' -AsPlainText -Force, that would be OK. And without the-Forceparameter, this would error with a similar error message -The system cannot protect plain text input. To suppress this warning and process the plain text secret, reissue the command specifying the Force parameter..