powershell - 使用Invoke-WmiMethod以特定用户的身份在远程计算机上运行可执行文件

标签 powershell impersonation

作为某些部署自动化的一部分,我试图使用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-PSSessionInvoke-CommandCredSSP身份验证一起使用,因为您似乎遇到了双跳身份验证问题。

检查我对以下问题的回答,以了解如何设置和使用CredSSP,这非常简单。

Running batch file on Remote Computers using PowerShell 2.0

关于powershell - 使用Invoke-WmiMethod以特定用户的身份在远程计算机上运行可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19109456/

相关文章:

powershell - 打开命令提示符以访问 USB 连接的 Windows 手机的文件夹

python - 将对象从 Python 流式传输到 PowerShell?

powershell - Windows 10,重命名所有子目录中的所有* .jpg文件,编号从1开始

powershell - Azure Powershell : Get-AzureKeyVaultSecret : Operation "get" is not allowed

c# - 在 ASP.NET MVC 中模拟用户进行测试

asp.net - 无法使用模拟开始监视 global.asax .net 3.5 Web 服务上的更改

c# - 模拟以更新 ASP.NET 表单例份验证站点中的用户 AD 信息

尽管禁用模拟,但 ASP.NET aspx 页面代码仍以模拟方式运行

c# - C# .NET Framework API(不是 Win32 API)中的 CreateProcessAsUser()

powershell - 将参数传递给函数: Cannot bind argument to parameter