This is an example project of how to create a single EXE file for distribution of a PowerShell script without needing to install PowerShell 7.5.4 on target machines.
This project is intended for demo purposes only and has not been written, tested, or designed for production environments.
This was implemented quick and dirty. Don't expect a polished, white-glove experience.
There will be no free support for this project. GitHub issues will be ignored and/or immediately closed. Do not ping the author(s) or maintainer(s) here or elsewhere for help, questions, assistance, etc. You use this project at your own risk and without assistance.
Pull requests are welcome, but there is no active support for this project. Your PRs may go unanswered for an indeterminate amount of time. PRs with excessive pings for review will be closed without review.
- Script.ps1 is embedded in the program assembly as a manifest resource at build time.
- The PSToExe.csproj file has the required settings to publish the app as a single, self-contained exe file.
- The program itself uses Hosted PowerShell (Microsoft.PowerShell.SDK) to run the embedded script.
- Edit the
Script.ps1with your desired PowerShell script - Build and publish
Download and install the .NET 10 SDK.
dotnet publish -o .\publish\You will then have the .\publish\PSToExe.exe file ready for distribution on 64-bit Windows.
Run the resulting EXE
.\PSToExe.exeYou only need to distribute the single EXE file. No additional files or prerequisite installs are required.
- The resulting EXE file will be over 100MB.
- Everything is done non-interactive so you cannot use commands like
Get-CredentialorRead-Host - The entire user script is piped to Out-String.
- Output order is not guaranteed to be the same as seen in a PowerShell console session.
- This has been barely tested beyond some basic PowerShell commands. Expect a bunch of things to not work as expected.
- 64-bit Windows only
- LICENSE - The No-AI MIT License for this project.
- README.md - Read me file.
- Script.ps1 - The PowerShell script to embed and run on target systems.
- Program.cs - The main C# program that runs Script.ps1 in Hosted PowerShell.
- PSToExe.csproj - C# project file. Contains the settings for single EXE file publishing.
- PSToExe.slnx - Visual Studio solution file.
- .gitignore - Git ignore configuration file.
Special thanks to @SeeminglyScience and @jborean93 for some amazing suggestions, simplifications, and being amazing soundboards.