Quantcast
Channel: Unable to evaluate Powershell password via interpolation - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Unable to evaluate Powershell password via interpolation

$
0
0

I am using Powershell to request a password from a user if not provided, based upon another answer. I then pass the password (no pun intended) to some program, do-something.exe. Rather than have an intermediate variable, I tried to convert the password to a normal string "inline":

[CmdletBinding()]Param(  [Parameter(Mandatory, HelpMessage="password?")] [SecureString]$password)do-something password=${[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))}

That doesn't work. I could only get it to work using a temporary, intermediate variable:

[CmdletBinding()]Param(  [Parameter(Mandatory, HelpMessage="password?")] [SecureString]$password)$pwd=[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))do-something.exe password=$pwd

Did I make a mistake trying to evaluate the password inline when invoking do-something.exe? How can this be done?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images