通过VB程序集中的掩码用户输入在Powershell中调用

时间:2015-03-11 04:02:16

标签: vb.net powershell

我有一个powershell脚本,希望用户输入密码。它调用一个函数来获取用户输入的弹出框。现在它是纯文本。我希望它被隐藏/掩盖

这是创建的功能:---

function Read-InputBoxDialog([string]$Message, [string]$WindowTitle, [string]$DefaultText)
{
    Add-Type -AssemblyName Microsoft.VisualBasic
    return [Microsoft.VisualBasic.Interaction]::InputBox($Message, $WindowTitle, $DefaultText)
}

这是我从powershell调用函数的方式:---

$SQLPassword = Read-InputBoxDialog -Message "Please enter SQL password used to connect to Database Server" -WindowTitle "Sql Server Authentication" -DefaultText "" 

如何将密码掩盖为****?

1 个答案:

答案 0 :(得分:2)

Powershell没有输入框,而是有自己的实现Get-Credential。它将凭证存储为安全字符串,因此获取明文密码需要进行一些调整。像这样,

$cred = Get-Credential -Message "Enter Sql password"
$cred.GetNetworkCredential().username # Show the username
$cred.GetNetworkCredential().password # Show the password