0

我正在尝试从 TeamCity Windows Slave 运行 powershell 脚本到另一台服务器以部署我的应用程序。

这是构建配置:

username = "<username>"
$password = "<password>"
$secstr = New-Object -TypeName System.Security.SecureString; 
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr;
Invoke-Command -ComputerName "<computer_name>" -Credential $cred -FilePath "deploy.ps1"

我收到以下错误。

following error message : Logon failure: unknown user name or bad password. 
[13:57:52]  [Step 1/1] For more information, see the about_Remote_Troubleshooting Help topic.

我只使用了正确的用户名和密码。我还检查了本地用户安全策略。我错过了什么吗?

4

1 回答 1

0

它只是一个粘贴错误,错过了用户名中的 $ 吗?用户名和密码在脚本之外可以正常工作吗?变量是否被正确替换。日志显示吗?我以前从未使用过该构造来制作凭据。这里提到的这个不起作用。

https://pscustomobject.github.io/powershell/howto/PowerShell-Create-Credential-Object/

于 2020-05-22T19:35:37.843 回答