【发布时间】:2017-06-13 22:10:30
【问题描述】:
我使用 Microsoft Bot Framework 创建了一个 Bot 应用程序,并希望实现以下目标:
- 无需任何身份验证即可在远程计算机上执行 Powershell 脚本
- powershell 脚本将托管在 Azure 或数据库(可能是任何数据库)上
到目前为止我已经完成了以下操作:
- 能够在远程计算机上手动执行 Powershell 脚本
- 能够使用 C# 代码在本地执行 Powershell 脚本
以下是我当前的代码:
WSManConnectionInfo connectioninfo = new WSManConnectionInfo();
connectioninfo.ComputerName = "<remote computer hostname>";
Runspace runspace = RunspaceFactory.CreateRunspace(connectioninfo);
//runspace.Open();
using (PowerShell ps = PowerShell.Create())
{
var re = ps.AddScript("Get-Service");
var results = re.Invoke();
}
【问题讨论】:
-
远程计算机的所有者是谁?它们是否完全在您的控制范围内 - 您是否为它们管理安全策略?
-
如果远程计算机启用了PSRemoting,您可以使用Invoke-Command。
-
嗨 Dylan/James,我不是远程计算机的所有者。我将创建一个管理员,Bot 可以通过该管理员登录远程计算机并执行管理工作。 Invoke-Command 在 powershell 窗口和手动干预下工作正常。我正在寻找一种通过 C# 代码进行自动远程处理的方法。
-
@zee 你现在碰巧解决了这个问题吗?我和你的情况完全一样。真的需要这方面的帮助......
标签: c# powershell botframework