# How to convert a powershell script to opensource .exe?

To make an installation of opensource software for the Windows platform single click, I am trying to convert the setup.ps1 into a setup.exe file. (To make a powershell script executable in a single (double) click, the user might/is still required perform additional actions). So to do that I downloaded PS2Exe from https://gallery.technet.microsoft.com/scriptcenter/PS2EXE-GUI-Convert-e7cb69d5. After running the following command in the correct folder in powershell:

.\ps2exe.ps1 .\setup.ps1 .\target.exe


The exe is indeed created. But upon inspection I found that the target.exe file is not inspectable with e.g. Winrar, whereas the latest installer of Eclipse, eclipse-inst-win64.exe, is.

Hence my question is: How can I convert the setup.ps1 to a single click setup.exe that is inspectable*/opensource?

*With inspectable, I mean a computer illiterate can still relatively easily see what the original lines of code and files are, e.g. no bytecode/no assembly etc.

Approaches

1. Thanks to the comments, I learned the reason the eclipse installer that is used as an example, consists of a self extracting zip file. After a short inspection I have not yet found an example of a self extracting zip file that is able to execute a powershell script without requiring user input. Such an example could suggest a feasible solution would be to create a self extracting zip that executes the setup.ps1 but it appears unlikely.
2. Wix installer has an option to include powershells into an MSI file.

2.1 I have yet to determine whether it is also able to create a setup.exe file that allows the setup.ps1 to be execute, and whether it can execute the powershell without requiring extra user actions.

2.2 I have yet to determine whether the setup.exe is (easily) reverse-engineerable, it appears ORCA is able to reverse engineer an MSI installer file, but I am not yet sure whether that qualifies as "Open Source" as it might be possible that different code/file combinations yielded the same MSI.

3. Based on https://4sysops.com/archives/creating-an-exe-for-your-powershell-scripts-using-winrar/ as suggested in the comments, I created an exe with sfx that unpacks the setup.ps1 file to: E:/some folder with a space/ using comments:
Path="E:\some folder with a space\target/"
SavePath
Setup=C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -sta -noexit -noprofile -executionpolicy bypass -file "E:\some folder with a space\target\setup.ps1"
Silent=1
Overwrite=1


without adding an icon. However when the exe is executed it returns:

    Windows PowerShell

lxrun : The term 'lxrun' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At E:\18-09-19 Document structure\personal\Programming\tools\powershellToExe\target\setup.ps1:1
char:1
+ lxrun /install /y
+ ~~~~~
+ CategoryInfo          : ObjectNotFound: (lxrun:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException 


Much like powershell is in a different path than the setup.ps1 script that is executed. When I open a powershell via Start>Powershell, enter E:followed by cd "E:\some folder with a space\target" and run./setup.ps1the unpackedsetup.ps1 runs fine. So I checked with command:

[bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")


The content of the powershell script is:

lxrun /install /y
lxrun /setdefaultuser testlinuxname /y
lxrun /setdefaultuser root /y
bash -c "echo 'testlinuxname:mypassword' | chpasswd"
bash -c "sudo echo 'testlinuxname ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers"
wsl sudo apt update
bash -c "echo 'yes' | sudo apt install default-jre"
lxrun /setdefaultuser testlinuxname /y
Read-Host -Prompt "Press Enter to exit"


To investigate the possible reason for the execution difficulties the SFX conversion from ps1 to exe yield, I will include an echo of the current directory in the setup.ps1 to inspect the paths which powershell works in.

• you can only see the "code" because eclipse-inst-win64.exe is a self extracting zip. – Ewan Aug 2 '19 at 10:19
• @Ewan, thank you. I could not find any examples of a self extracting zip executing a powershell script. I will use your comment to include approaches in my question. – a.t. Aug 2 '19 at 10:27
• 4sysops.com/archives/… – Ewan Aug 2 '19 at 10:29

Credits go to @Jotunn and @Ewan. As listed in the link provided by @Ewan, the answer of @Jotunn provided a solution. Powergui allows conversion of setup.ps1 to setup.exe. The verified steps as described are:
Then your powershell script gets executed in a Console Window Host if you run it. The compiled setup.exe is still inspectable by for example winrar.