Recently, I released the first version of the PowerShell Pro Tools PowerShell module to the PowerShell gallery. The module contains a PowerShell cmdlet wrapper around PSPack.exe that is capable of packaging scripts into executables. This version of PSPack.exe also supports the ability to bundle multiple PS1 files into a single PS1 file.

In this post we will look at how the bundling works.

An Example Set of Scripts

Assume that I have a set of PowerShell scripts.

Organizing scripts in this way is helpful to breakdown the size of the solution and to avoid duplicating code. The root script includes a bunch of other scripts via dot sourcing.

Scripts included in the root script may dot source additional scripts.

Running the scripts results in the executable of each of the dot sourced scripts.

Bundling Scripts

Although having a bunch of scripts for development may be advantageous, having a set of scripts complicates the deployment process. Using Merge-Script, you can now combine the set of scripts into a single PS1 file or .NET executable.

Using the the following command line, I can produce a single PS1.

The resulting script is simply a combination of all the dot sourced scripts in the tree of scripts.

Creating an Executable

The above example skips the compilation step. Changing the OutputType of the command above results in an executable rather than a script.

The resulting exe behaves the same way as the bundled PS1 file.

Let me play you some Wonderwall…