如何使用Powershell的读取主机功能接受外部服务的密码? [英] How can I use powershell's read-host function to accept a password for an external service?

查看:107
本文介绍了如何使用Powershell的读取主机功能接受外部服务的密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个脚本,该脚本与SOAP服务建立连接.建立连接后,我需要在我发送的每个命令中都传递一个用户名/密码.我的问题是,当我使用读取主机执行此操作时,我的密码以明文形式显示并保留在外壳中:

I have a script I'm writing that makes a connection to a SOAP service. After the connection is made, I need to pass in a the username/pass with every command I send. The problem I have is that when I use read-host to do this, my password is shown in cleartext and remains in the shell:

PS C:\Users\Egr> Read-Host "Enter Pass"
Enter Pass: MyPassword
MyPassword

如果我使用-AsSecureString隐藏它,那么该值将不再传递给服务,因为它现在是System.Security.SecureString对象:

If I hide it with -AsSecureString, the value can no longer be passed to the service because it is now a System.Security.SecureString object:

PS C:\Users\gross> Read-Host "Enter Pass" -AsSecureString
Enter Pass: **********
System.Security.SecureString

当我通过此操作时,它不起作用.我不在乎以明文形式将密码传递给服务的密码,我只是不希望密码输入用户的密码后仍停留在用户的外壳上.是否可以隐藏读取主机"输入,但仍将密码存储为明文?如果没有,是否可以将System.Security.SecureString对象作为明文传递?

When I pass this, it does not work. I don't care about the passwords being passed to the service in cleartext, I just don't want them sticking around on a user's shell after they enter their password. Is it possible to hide the Read-Host input, but still have the password stored as cleartext? If not, is there a way I can pass the System.Security.SecureString object as cleartext?

谢谢

推荐答案

$ Password是一个安全字符串,它将返回纯文本密码.

$Password is a Securestring, and this will return the plain text password.

[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password))

这篇关于如何使用Powershell的读取主机功能接受外部服务的密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆