2016-11-09 29 views
2

我正在尋找一種方法來隱藏來自Read-Host cmdlet的用戶輸入。是否可以在Powershell中隱藏讀主機的用戶輸入?

我知道我可以用-assecurestring來做到這一點,但我想將輸入保存爲純文本的變量。

有沒有可能的方法來做到這一點?

+0

http://stackoverflow.com/questions/15007104/how-can-i-use-powershells-read-主機功能,即表示接受-A-密碼換了,EXTERN –

回答

3

您必須使用-AsSecureString開關,但你也可以檢索明文值:

$securedValue = Read-Host -AsSecureString 
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($securedValue) 
$value = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr) 
相關問題