Skip to content

Instantly share code, notes, and snippets.

@SeeminglyScience
Created October 14, 2017 18:29
Show Gist options
  • Save SeeminglyScience/ab92ef174eb57809011804bd3857574f to your computer and use it in GitHub Desktop.
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
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