我的问题是我制作了一个启动 Exchange shell PSsession 的脚本。如果我在 PowerShell 中逐行执行脚本,或者在资源管理器中右键单击它并运行,脚本运行良好。但是,在生成新证书后通过 certify 调用它时会失败。
这是脚本的部分:
$password = Get-Content -Path 'c:\Certificate_Update\securepassword.txt'
$pw = ConvertTo-SecureString -String $password
#$pw = ConvertTo-SecureString -AsPlainText -Force -String "admin pass here"
$cred = New-Object System.Management.Automation.PSCredential ("Wookies-Domain\Administrator", $pw)
$uri = 'http://Exchange-Server/PowerShell/'
# Starts remote Exchange shell session
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $uri -Authentication Kerberos -Credential $Cred
# Imports remote Exchange shell session to this Machine
Import-PSSession $Session
我得到的错误是:
ConvertTo-SecureString : 系统找不到指定的路径。
在 C:\Certificate_Update\Update_Old_Cert.ps1:40 char:7
+ $pw = ConvertTo-SecureString -String $password
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [ConvertTo-SecureString], CryptographicException
+ FullyQualifiedErrorId : ImportSecureString_InvalidArgument_CryptographicError,Microsoft.PowerShell.Commands.ConvertToSecureStringCommand
TerminatingError(New-Object):“异常调用“.ctor”与“2”参数:
“无法处理参数,因为参数“密码”的值为空。
将参数“密码”的值更改为非空值。""
新对象:使用“2”参数调用“.ctor”的异常:“无法处理
参数,因为参数“密码”的值为空。更改值
将“密码”参数设置为非空值。”
它是说$password是空的?无法弄清楚我做错了什么。当脚本由certify运行时,它可能是一些权限吗?