I have created a Bot Application using Microsoft Bot Framework and want to achieve the following:
- To execute a Powershell script on remote computers without any authentication
- The powershell scripts will be hosted on Azure or on a Database (may be any)
I have done following till now:
- Was able to execute Powershell scripts on remote computers manually
- Was able to execute Powershell scripts locally using C# code
Below is my current code:
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();
}
I think that you are missing the bind of your
PowerShell
instance to the runspace.Take a look to this for more details.
Alternatively, you can create a Pipeline (as explained here) using the runspace and invoke the commands.