Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 在弹出窗口中读取主机的最简单方法?_Powershell_User Interface - Fatal编程技术网

Powershell 在弹出窗口中读取主机的最简单方法?

Powershell 在弹出窗口中读取主机的最简单方法?,powershell,user-interface,Powershell,User Interface,我有一个客户端vpn的密码,需要从命令行重复键入。我不想将它存储在磁盘上,而是希望在我的powershell$配置文件中查询它,将它存储在shell实例范围内的变量中,然后在其他脚本中重用它(以便它只存在于内存中) 我可以使用Read Host来查询密码,但我更喜欢弹出对话框(Paegent已经弹出了一个对话框,我已经习惯了alt+tab'ing的工作流程,在我重新启动计算机时通过这些对话框输入密码) 要达到与读取主机相同的效果,最简单的方法是什么?只需一个小的弹出对话框?回到旧的vb上,我想到

我有一个客户端vpn的密码,需要从命令行重复键入。我不想将它存储在磁盘上,而是希望在我的powershell$配置文件中查询它,将它存储在shell实例范围内的变量中,然后在其他脚本中重用它(以便它只存在于内存中)

我可以使用
Read Host
来查询密码,但我更喜欢弹出对话框(Paegent已经弹出了一个对话框,我已经习惯了alt+tab'ing的工作流程,在我重新启动计算机时通过这些对话框输入密码)


要达到与读取主机相同的效果,最简单的方法是什么?只需一个小的弹出对话框?

回到旧的vb上,我想到了一些简单的方法,似乎可以工作

  > [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic")
  > $clientPassword = [Microsoft.VisualBasic.Interaction]::InputBox("OPassword?", "Client VPN")

我将使用
Get Credentials
屏蔽密码,然后从凭据中提取密码

#Open credential-box that masks your password when you write it.
#The inputs aren't verified, so you can use whatever username you want if it doesn't matter.
$cred = Get-Credential $env:USERDOMAIN\$env:USERNAME

#Get password
$password = $cred.GetNetworkCredential().Password

#View password
$password
TestPassword123
如果您只需要密码,则可以将其缩短为:

$password = (Get-Credential $env:USERDOMAIN\$env:USERNAME).GetNetworkCredential().Password

获取凭证弹出一个对话框,您可以填写帐户名,并在顶部提供提示消息。另外,它在输入密码时屏蔽了密码。这一点很好,不过在我的情况下,我想我宁愿让密码保持透明,以查看输入错误