Giving PowerShell scripts to people often results in questions like, “How do I start this?” or “I ran this, but nothing happens…” (When sending a script that contained a function). In this blog post, I will show you how to create an executable of a script and its limitations.
What are executables?
“In computing, an executable is a resource that a computer can use to control its behavior. As with all information in computing, it is data, but distinct from data that does not imply a flow of control.[2] Terms such as executable code, executable file, executable program, and executable image describe forms in which the information is represented and stored. A native executable is machine code and is directly executable at the instruction level of a CPU.[3][4] A script is also executable although indirectly via an interpreter. Intermediate executable code (such as bytecode) may be interpreted or converted to native code at runtime via just-in-time compilation.”
Source: https://en.wikipedia.org/wiki/Executable
PowerShell to Exutable (PS2EXE)
I used this in the past, but got reminded about its existence again while at one of our customers 🙂 Back then, I used it by installing the module and running the command-line version, but there’s a nice GUI for it now, too, which makes things easier. (The Module can be found here, and the GitHub page here.) Both the module and the GUI version were made by Ingo Karstein and Markus Scholtes.
Note: It only works on PowerShell version 5!
How to install
You can install it by either:
- Downloading all the files from the GitHub repository by using this link to create a ZIP file and extract it to c:\temp\ps2exe, for example
- Cloning the repository using Git by running git clone https://github.com/MScholtes/Win-PS2EXE.git
- Installing the module by running Install-Module PS2EXE or Install-PSResource PS2EXE
Using the GUI version
After installing, you can start the GUI by running Win-PS2EXE

In the example below, I create a PSIF.exe from a simple Hello World output script, which I saved as c:\temp\psif.ps1:
Write-Host "Hello world!" pause

After selecting Compile, a PowerShell v5 window will appear:

And after running the psif.exe, this window appeared:

And after selecting Ok, the prompt for the pause statement appeared:

And after hitting Enter / Clicking OK, the executable terminated. Easy, straightforward, and more complex scripts also work. I saved my update-modules script and created an executable of that. Don’t check the compile a graphic Windows program… option, because every write-host prompt will give you a window that you have to click 🙂

Using the command-line version
Using the same example Hello world script, I used this command-line to create a psif.exe, too:

ps2exe is the alias for invoke-ps2exe, win-ps2exe and winps2exe.exe ar aliases, too 🙂

Command-Line parameters are the same as the GUI options, but there are a few more available, like DPI scaling options:

Issues
The issues that I’m aware of myself are:
- Anti-Virus programs might detect this as a Virus 🙂
- Only PowerShell v5, sometimes you have v7 things in your script…
- Running this on locked-down machines with PowerShell GPO or Intune profiles
Wrapping up
And that’s how you create executables from PowerShell scripts so that people can start or run them in Scheduled Tasks more easily. But don’t store credentials in them; the executable can be opened in a text editor!:

Have a lovely weekend!