I have a PowerShell script file (.ps1) that I need to convert into a Windows Executable file (.EXE). Here is a sample PowerShell script:
# This is a sample PowerShell script
# Define a variable
$greeting = "Hello, World!"
# Display the greeting
Write-Output $greeting
I am currently working on Ubuntu 22.04.2 LTS. To install PowerShell on Ubuntu, I followed these steps and successfully installed PowerShell, allowing me to run PowerShell scripts on my Ubuntu OS:
Run the following commands to install the required dependencies:
sudo apt-get install mono-complete
sudo wget -q https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
Update the package list:
sudo apt-get update
Install PowerShell:
sudo apt-get install -y powershell
Additionally, you can install PowerShell via Snap:
sudo snap install powershell --classic
Once PowerShell is installed, I installed PS2EXE through the PowerShell tool.
Install-Module -Name ps2exe
I am sure that PS2EXE should help me convert the PowerShell script to an executable file.
To convert the PowerShell script (sample.ps1) to an executable file (sample.exe), I used the following command in PowerShell:
ps2exe -OutputFile sample.exe sample.ps1
This process worked seamlessly on Windows OS, but on Ubuntu OS, I encountered the following error:
Operation is not supported on this platform.
PowerShell 7.3.4
PS /home/vboxuser/Documents/ocs> ps2exe -OutputFile test.exe test.ps1
PS2EXE-GUI v0.5.0.22 by Ingo Karstein, reworked and GUI support by Markus Scholtes
PowerShell Desktop environment started...
Reading input file /home/vboxuser/Documents/ocs/test.ps1
Compiling file...
MethodInvocationException: /home/vboxuser/.local/share/powershell/Modules/ps2exe/1.0.6/ps2exe.ps1:2678
Line |
2678 | $cr = $cop.CompileAssemblyFromSource($cp, $programFrame)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling "CompileAssemblyFromSource" with "2" argument(s): "Operation is not supported on this platform."
Invoke-ps2exe: Output file /home/vboxuser/Documents/ocs/test.exe not written