Skip to content

A little PowerShell function to create an executable from PowerShell

Notifications You must be signed in to change notification settings

nyanhp/ExeWrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PowerShell Executable Generator

Why

Every now and then I get asked "JHP, how can I create an executable from my PowerShell script?" While my go-to answer is "Don't do that!" it does not satisfy everyone.
This led me to quickly code this small .NET bit which is compiled together with the accompanying script file into one executable.

How

The small script at the moment only contains one function which could be dot-sourced, Save-CompiledScript. This function is very easy to use:

Save-CompiledScript -ScriptPath D:\BlogTester.ps1 -ExePath D:\blog.exe

It returns a System.IO.FileInfo object retaining the executable that has just been created.
In order to include additional dependencies the switch parameter IncludeFolderContents will include everything except the script itself in the resulting binary file.

Save-CompiledScript -ScriptPath D:\BlogTester.ps1 -ExePath D:\blog.exe -IncludeFolderContents

In the future this small script might grow. Since you probably would want to wrap more than a single script into an exe file, I will update it periodically to do more stuff.

Updates

  • 2018-09-14
    • Script has been streamlined to make use of Add-Type built-in functionality.
    • You can now select a ThreadApartmentState. We default to STA. Options are STA,MTA and Unknown.

About

A little PowerShell function to create an executable from PowerShell

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published