PowerShell Pro Tools supports packaging PowerShell scripts as executables. The packaging functionality creates a .NET executable and embeds the PowerShell script into the assembly. The .NET executable takes advantage of the PowerShell console host to run the script. The host supports accepting arguments from the command line and all the functionality of PowerShell.exe in your own custom executable.
Packaging enables easy distribution of PowerShell scripts in easy to consume executables. Scripts cannot be changed and can be provided to end users without the worry of what may happen if they modify them.
Assume we have a simple script that accepts a couple parameters and outputs to the screen.
To package the script as an executable, right click on the script in Solution Explorer and select Package as executable.
Output from the packaging process will be written to the Build output pane in the Output window.
The resulting executable will behave similar to PowerShell.exe but will pass arguments from the command line into your packaged script. Since the source script accepts a Message and a NumberOfTimes parameter in the above example, the host executable accepts these parameters as well.
Packaging Requires .NET Core SDK version 1.0.0 or higher and the .NET 4.6.2 Developer Pack installed.
Resulting executables can be run on machines running PowerShell v3 or greater.
Resulting executables run under the .NET 4.6.2 framework.