-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoShWithoutPoSh.cs
55 lines (29 loc) · 1.42 KB
/
PoShWithoutPoSh.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//Compliation:
//Win7x64: C:\Windows\Microsoft.NET\Framework64\v2.0.50727\csc.exe /r:C:\Windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll /unsafe /platform:anycpu /out:C:\Users\Public\prog.exe C:\Users\Public\prog.cs
//Win10x64: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /r:C:\Windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll /unsafe /platform:anycpu /out:C:\Users\Public\prog.exe C:\Users\Public\prog.cs
//Insert function call in end of powershell script eg. Invoke-AllChecks -Verbose | Out-File C:\Users\Public\allchecks.txt
//Usage: prog.exe "path_to_powershell_file"
using System;
using System.Configuration.Install;
using System.Runtime.InteropServices;
using System.Management.Automation.Runspaces;
public class Program
{
public static void Main( string[] args )
{
Mycode.Exec( args[ 0 ] );
}
}
public class Mycode
{
public static void Exec(string file)
{
string command = System.IO.File.ReadAllText( file );
RunspaceConfiguration rspacecfg = RunspaceConfiguration.Create();
Runspace rspace = RunspaceFactory.CreateRunspace( rspacecfg );
rspace.Open();
Pipeline pipeline = rspace.CreatePipeline();
pipeline.Commands.AddScript( command );
pipeline.Invoke();
}
}