mis*_*kin 27 powershell credentials
我正在做这篇文章中描述的将保存文件保存在安全文件中的内容,因此我们的自动化过程可以使用它通过Invoke-command运行远程PS脚本:http: //blogs.technet.com/b/robcost/archive/2008 /05/01/powershell-tip-storing-and-using-password-credentials.aspx
当我在我的帐户下运行时,这很有效 - 密码从加密文件中读取,传递给Invoke-command,一切都很好.
今天,当我的脚本准备好它的黄金时间时,我试图在自动进程将使用的Windows帐户下运行它,并在我的脚本尝试从文件中读取安全密码时遇到此错误:
ConvertTo-SecureString : Key not valid for use in specified state.
At \\remoted\script.ps1:210 char:87
+ $password = get-content $PathToFolderWithCredentials\pass.txt | convertto-sec
urestring <<<<
+ CategoryInfo : InvalidArgument: (:) [ConvertTo-SecureString], C
ryptographicException
+ FullyQualifiedErrorId : ImportSecureString_InvalidArgument_Cryptographic
Error,Microsoft.PowerShell.Commands.ConvertToSecureStringCommand
Run Code Online (Sandbox Code Playgroud)
要求我的同事在他的帐户下运行,他也得到了同样的错误.
这是我用来保存凭据的代码:
$PathToFolderWithCredentials = "\\path\removed"
write-host "Enter login as domain\login:"
read-host | out-file $PathToFolderWithCredentials\login.txt
write-host "Enter password:"
read-host -assecurestring | convertfrom-securestring | out-file $PathToFolderWithCredentials\pass.txt
write-host "*** Credentials have been saved to $pathtofolder ***"
Run Code Online (Sandbox Code Playgroud)
这是脚本中的代码,由自动进程运行以读取它们以在Invoke-command中使用:
$login= get-content $PathToFolderWithCredentials\login.txt
$password = get-content $PathToFolderWithCredentials\pass.txt | convertto-securestring
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $login,$password
Run Code Online (Sandbox Code Playgroud)
行上发生错误$ password = get-content $ PathToFolderWithCredentials\pass.txt | 的ConvertTo-SecureString的
有任何想法吗?
man*_*lds 23
ConvertFrom-SecureString
采用Key
(和SecureKey
)参数.您可以指定用于保存加密标准字符串的密钥,然后再次使用该密钥ConvertTo-SecureString
来获取安全字符串,而不管用户帐户如何.
http://technet.microsoft.com/en-us/library/dd315356.aspx
在一个项目中,我实现了非对称加密,人们使用公钥加密密码,自动化过程具有解密密码的私钥:处理生产配置中的密码以进行自动部署
Mic*_*ele 21
您必须在同一台计算机上创建密码字符串,并使用与运行它相同的登录名.
归档时间: |
|
查看次数: |
81010 次 |
最近记录: |