-
Notifications
You must be signed in to change notification settings - Fork 139
/
unmanagedps.cs
41 lines (38 loc) · 1.11 KB
/
unmanagedps.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Collections.ObjectModel;
using System.Management.Automation.Runspaces;
namespace unmanagedps
{
class Program
{
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder();
try
{
Runspace rs = RunspaceFactory.CreateRunspace();
rs.Open();
RunspaceInvoke ri = new RunspaceInvoke(rs);
Pipeline pipe = rs.CreatePipeline();
pipe.Commands.AddScript(args[0]);
pipe.Commands.Add("Out-String");
Collection<PSObject> output = pipe.Invoke();
rs.Close();
foreach (PSObject line in output)
{
sb.AppendLine(line.ToString());
}
Console.WriteLine(sb.ToString());
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}