Created
October 14, 2017 18:29
-
-
Save SeeminglyScience/ab92ef174eb57809011804bd3857574f to your computer and use it in GitHub Desktop.
Very simple example of creating a silent executable that runs a PowerShell script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function New-PowerShellApp { | |
[CmdletBinding()] | |
param([string]$FilePath, [string]$Script) | |
end { | |
$Script = $Script -replace '"', '""' | |
Add-Type -OutputType WindowsApplication -OutputAssembly $FilePath -TypeDefinition @" | |
using System.Management.Automation; | |
namespace SilentPowerShell | |
{ | |
public static class Program | |
{ | |
public static void Main() | |
{ | |
using (var ps = PowerShell.Create()) | |
{ | |
ps.AddScript(@"$Script").Invoke(); | |
} | |
} | |
} | |
} | |
"@ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment