Specifying a secure string on the command line - by Shay Levi

Status : 


Sign in
to vote
ID 773183 Comments
Status Active Workarounds
Type Suggestion Repros 0
Opened 12/1/2012 2:36:43 AM
Access Restriction Public


Consider the following function

function foo


If I specify the password  I get an error (expected)

PS> foo -name shay -password onlyme
foo : Cannot process argument transformation on parameter 'password'. Cannot convert the "onlyme" value of type
"System.String" to type "System.Security.SecureString".
At line:1 char:15
+ foo -password onlyme
+               ~~~~~~
    + CategoryInfo          : InvalidData: (:) [foo], ParameterBindingArgumentTransformationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,foo

But if I leave it out, PowerShell prompts me to supply mandatory arguments, only now it do the transformation for me and it also mask the password. .

PS> foo

cmdlet foo at command pipeline position 1
Supply values for the following parameters:
password: ******

We can work around the error by explicitly converting the password to a secure string but I'd like to enjoy both worlds and suggest that PowerShell detect the parameter type and behave just as if the parameter was missing, allowing me to type masked password on the command line and also converting it.

PS> foo -name shay -password *******
Sign in to post a comment.