Convert PowerShell .ps1 Scripts to .exe

Aidan Palmer
3 min readFeb 4, 2023

In my last post I went over how to change permissions in PowerShell in order to run scripts, since PowerShell does not allow script execution with its default settings. But then, after some research, I found that there is another way of getting around PowerShell’s default settings — convert the script into a .exe executable file. This can be done with scripts written in Bash, Python, or another language, but I am only going to go over how to do this with a PowerShell script.

Converting a PowerShell script into an executable file allows someone to easily transfer over that script to another computer, and that computer can then run the script without having to change the script execution policy in PowerShell, thus saving yourself another step. There is also no need to use the command line, so your average PC user can simply double click on the file and run the script.

We are going to be installing a tool called PS2EXE, an open-source, free PowerShell module that converts .ps1 scripts to the .exe format — all on the command line. There is also a GUI version available that I have not used.

First, run PowerShell as an administrator.

Enter the following command:

Install-Module ps2exe

You will get a prompt warning that it is an untrusted repository. Enter Y. Don’t be alarmed, the module is completely safe to install.

Now that the module is installed, we can test it out by converting a .ps1 script to a .exe file.

Invoke-ps2exe "script.ps1" "script.exe" -noConsole

Note that you will have to provide the full path to the script if you are not already in that directory. You can also name the executable whatever you want when you convert it; it does not have to be the same name as the .ps1 script.

I added in the -noConsole option at the end, because without it a PowerShell console will appear, which we don’t need. Now you can simply navigate to your new executable file in File Explorer and double click on it like with any other program.

Note that an antivirus program might prevent you from opening up your new executable file, so you might have to disable that before you can run the program. I haven’t had this problem with Windows Security, but MalwareBytes immediately quarantined my file when I tried to run it, which was a little annoying. I believe that there is a way to certify the executable so that it is not mistakenly detected as malware, but I have not looked into this. For more about PS2EXE, check out its GitHub page:

--

--

Aidan Palmer
0 Followers

I work in IT and like to write about anything tech-related that I find interesting.