我正在做这篇文章中描述的将保存文件保存在安全文件中的内容,因此我们的自动化过程可以使用它通过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 …Run Code Online (Sandbox Code Playgroud)