compiling powershell scripts on linux to portable executable

03945648 1 Reputation point
2022-11-16T16:49:36.417+00:00

Hi

Since Powershell is available on Linux.

Let's say I am a Linux (ubuntu) user, I installed PowerShell on my system with snap, etc
and I have a simple file script.ps1
echo "hi"

Now assume I want to send this to someone else to run it on their machine without having to install Powershell on their machine.

is there a way to compile my script1.ps to some binary executable file on Linux?

Something close to what ps2exe does on windows...

Thanks

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,364 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Hoekstra Jelle 491 Reputation points
    2022-11-16T18:40:59.46+00:00

    Hi!

    You could try running the following on the linux machine: pwsh

    It should open up a Powershell prompt, but I am not sure if a seperate installation would be required.

    Is there a way to compile my script1.ps to some binary executable file on Linux? -> I think not. Here's why:
    In core an exe file is still windows based, as is powershell is windows based, it makes sense this is supported. @Digivill I know there are tools available to do so for bash scripts as well as python. It might be worth looking into if your main platform is Linux. And going for the full cross-platform experience you could also checkout C#, but it might take some time coming from PS.

    Hope this helps!

    0 comments No comments

  2. 03945648 1 Reputation point
    2022-11-16T22:56:11.067+00:00

    Hey

    Thanks for your reply

    You could try running the following on the linux machine: pwsh

    Sure I can try, but ofc it won't work unless powershell is installed on that machine.

    an exe file is still windows based

    I am aware ".exe" as an executable is purely a windows thing. Of course a .exe compiled for windows won't work on linux, I just referred to ".exe" as en example. On Linux there is no particular extension for executable files (.exe, .out, .bin are common ones) it is mostly a permission type, if you +x a file it can be executed, that's it.

    I know there are tools available to do so for bash scripts as well as python.

    Bash is not native to Windows, so same thing (Use bash not native to windows, use PS, not native to Linux). I know how to write C++, or python cross-platform apps as you mentioned, and compiling them is relatively easy. that is not really the problem...

    Just thought I would ask before porting the code to know what my options are and if PS on Linux made tit his far.

    Thanks again for your input!

    0 comments No comments