Invoking a PowerShell Script from LINQ
Hello,
Is it possible to invoke a PowerShell script a server with C# from within LINQPad?
Specifically, I would like to run a PowerShell command like this:
(new-object Net.WebClient).DownloadString('http://anywebsite.net/release/powershellscript.ps1') | iex
Many thanks.
Kind regards,
Dominik
Is it possible to invoke a PowerShell script a server with C# from within LINQPad?
Specifically, I would like to run a PowerShell command like this:
(new-object Net.WebClient).DownloadString('http://anywebsite.net/release/powershellscript.ps1') | iex
Many thanks.
Kind regards,
Dominik
Comments
For instance, the following executes the Get-Process command and dumps the results to a data grid with hyperlinks that you can explore further. You could use as a starting poing to write a PSExec method:
var runspaceConfiguration = RunspaceConfiguration.Create(); var runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration); runspace.Open(); RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace); Pipeline pipeline = runspace.CreatePipeline(); Command myCommand = new Command("Get-Process"); pipeline.Commands.Add(myCommand); pipeline.Invoke().Select (pso => pso.BaseObject).Dump(true);
Many thanks for your support, I appreciate it very much.
I wasn't far away from your solution...
Regards,
Dominik