作为某些部署自动化的一部分,我试图使用Powershell在远程计算机上运行可执行文件。可执行文件需要以特定用户身份运行,以便它可以连接到适当的数据库以执行其工作。
例如,Powershell脚本以用户“Org \ TFSUser”的身份在Machine1上运行。它需要以“Devel \ BuildServices”用户身份在Machine2上运行可执行文件。我正在尝试使用Invoke-WmiMethod命令集在远程服务器上启动可执行文件,如下所示。这似乎起作用,因为它在远程计算机上运行了可执行文件,但是使用了匿名用户登录名。我在日志中看到的错误是System.Data.SqlClient.SqlException: Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
$username = "devel\BuildServices"
$password = cat Deploy\SecurePasswords\PasswordForBuildServicesAsSecureString.txt | convertto-securestring
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
Invoke-WmiMethod -class Win32_process -name Create -ArgumentList ("C:\TeamCityDeployments\Importer\Importer.exe -pFile:C:\TeamCityDeployments\Importer\alphaParams.txt >> importer.log") -ComputerName "Machine2.devel" -Impersonation 3 -EnableAllPrivileges -Credential $cred
要使用密码构建凭据对象而不提示您,我使用了指定的安全字符串here。
在Invoke-WmiMethod中,我提供了指定的here参数“-Impersonation 3”。我的理解是,这将启动远程过程,同时模拟我要传递的用户凭据。
谁能告诉我如何使用特定用户的凭据在远程计算机上运行可执行文件。
最佳答案
尝试将New-PSSession
和Invoke-Command
与CredSSP
身份验证一起使用,因为您似乎遇到了双跳身份验证问题。
检查我对以下问题的回答,以了解如何设置和使用CredSSP,这非常简单。
Running batch file on Remote Computers using PowerShell 2.0
关于powershell - 使用Invoke-WmiMethod以特定用户的身份在远程计算机上运行可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19109456/