Powershell to EXE –
Method 1: Using the PS2EXE Module (Recommended)
This method packages your script into a lightweight executable wrapper. You can do this entirely via the command line or use its built-in graphical interface (GUI).
Step 1: Install PS2EXE
Open PowerShell as an Administrator and run the following command to download the module from the Microsoft PowerShell Gallery:
powershell
Install-Module -Name ps2exe -Scope CurrentUser
Use code with caution.
(If prompted to trust the repository, type Y or A for Yes/All).
Step 2: Convert Your Script
Option A: Using the Command Line (Fastest)
Run the Invoke-ps2exe command by specifying your source file and your desired output path:
powershell
Invoke-ps2exe -inputFile "C:\path\to\script.ps1" -outputFile "C:\path\to\program.exe"
Use code with caution.
- 💡 Useful Flags:
- Add
-noConsoleif your script has a graphical user interface (GUI) and you want to prevent the black PowerShell console window from popping up. - Add
-iconFile "C:\path\to\icon.ico"to give your executable a custom icon.
- Add
Option B: Using the Graphical Interface (Easiest)
If you prefer a visual interface to select files and configure settings, type this into PowerShell:
powershell
Win-PS2EXE
Use code with caution.
A window will pop up allowing you to easily browse for your .ps1 file, pick an output destination, assign an icon, and check configuration boxes before compiling.
Method 2: Using the Built-In Windows Tool (IExpress)
If you are on a restricted machine where you cannot install external PowerShell modules, you can use IExpress, a legacy packaging utility built into Windows.
- Press
Win + R, typeiexpress, and hit Enter (Run as Administrator). - Choose Create new Self Extraction Directive file and click Next.
- Select Extract files and run an installation command.
- Package Title: Enter a name for your application.
- Confirmation/License: Select “No prompt” and “Do not display a license”.
- Packaged files: Click Add and select your
.ps1script. - Install Program to Launch: In the Install Program box, paste the following command (replace
myscript.ps1with your actual file name):cmdpowershell.exe -ExecutionPolicy Bypass -File myscript.ps1Use code with caution. - Show window: Select Hidden if you don’t want a command window flashing.
- Finished message: Select “No message”.
- Package Name and Options: Click Browse to choose where to save your final
.exefile. Check “Hide File Extracting Progress Animation”. - Choose “No save” for the SED file, and advance to the final screen to compile your executable.