Technical Anshu
Tutorials Blog
Step by Step

PS2EXE Step by Step From PS1 File to Working EXE

Four stages turn a finished PowerShell script into a working EXE: test the script, install the free PS2EXE module, run one command (or click through the GUI), and test the result the way a user will. Each stage is short - the discipline is in not skipping the test stages.

By Technical AnshuWindows 10 / 115 minute read
Watch the video to see each stage performed on screen in order

People ask for the conversion command as if it were the whole job. It is one line in stage three of four. The stages before and after it - testing the script, then testing the EXE - are where conversions succeed or quietly fail. Here is the complete order, with the exact commands, ready to copy.

Windows PowerShell - the conversion, in order
1 Test Cleanup.ps1 until it runs clean 2 Install-Module -Name ps2exe 3 Invoke-PS2EXE -inputFile ".\Cleanup.ps1" -outputFile ".\Cleanup.exe" 4 Test Cleanup.exe by double-clicking it
Four stages, and the two test stages matter more than the two tool stages. Commands are copy-paste ready.
1

Stage 1 - Finish the Script First

The conversion freezes your script into a program, so freeze a finished one. Run the .ps1 start to finish, on a normal account and an admin account, and read every line of its output. Any error you ship inside an EXE becomes ten times slower to diagnose, because the user sees a window close - or nothing at all - instead of an error message you can ask about.

2

Stage 2 - Install the Module

  1. Open PowerShell (your own working window is fine)
  2. Run Install-Module -Name ps2exe
  3. Accept the PSGallery trust prompt if it appears - you are installing the well-known community module by name, from the official gallery
  4. If installs are blocked by policy on your machine, use Set-ExecutionPolicy -Scope CurrentUser RemoteSigned on your own account, and note that you changed it

This install happens once, on the machine that builds EXEs. Target PCs need nothing.

3

Stage 3 - Convert, Command Line or GUI

Command line, one instruction:

  1. Invoke-PS2EXE -inputFile ".\Cleanup.ps1" -outputFile ".\Cleanup.exe"
  2. The alias ps2exe with the same parameters does the identical job
  3. Add options on the same line as needed - -noConsole, -requireAdmin, -iconFile, -title, -version

Prefer clicking? Run Win-PS2EXE and the same choices appear as a form: pick the input file, the output file, tick the options, press Compile. The video on this page shows the graphical route being used, which is why most people start there - the output file is exactly the same either way.

4

Stage 4 - Test Like the Real User

  1. Move the EXE somewhere neutral - the Desktop or a shared folder
  2. Double-click it; do not launch it from your PowerShell window
  3. If it needs admin rights, confirm the UAC prompt appears and the tool completes after it
  4. Let one real user try it before you announce it to everyone

Then file the pair together - script and EXE, same folder, same version in the name if your team is informal. When the script changes, re-run stage 3 and replace the EXE; never edit around a stale build.

Watch the Complete Process in the Video

Watch the video to see this exact sequence performed - install, GUI options, compile and run.

Watch Full Video
Frequently Asked Questions

The install command says the gallery is untrusted. Should I worry?

That prompt appears the first time anyone installs a module from the PowerShell Gallery, and it is Windows asking you to confirm the source once. If you typed Install-Module -Name ps2exe yourself, answering Yes is the normal, expected step. If a random script ever asks you to trust a gallery you have never heard of, that is the time to stop.

Can I convert a script that asks the user questions?

Yes, if the questions are console prompts or Windows forms the script already shows. Keep the console version (do not use -noConsole) for prompt-based scripts, or the user will see nothing and the EXE will appear frozen while it waits for input it cannot receive.

The GUI and the command made different file sizes. Did something go wrong?

No. Options change the package - console versus no-console hosts, embedded icon and version data all change the size slightly. What matters is behaviour: test the EXE you actually plan to ship, built with the exact options you plan to ship.

This guide is based on the Technical Anshu PowerShell to EXE video - Stuck on any step? Ask in the video comments and you will get a reply there.