2

I am trying to automatically "compile" my ps1 script to .exe file on push. So I wrote the yml file to install ps2exe then run it on the script file that is in root of my repo.

I took the PSScriptAnalyzer from the demo and modified it.

name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 
on: [push]
jobs:
  Run-PSScriptAnalyzer-on-Windows:
    name: Run PSScriptAnalyzer on Windows
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install PSScriptAnalyzer module
        shell: pwsh
        run: |
          Set-PSRepository PSGallery -InstallationPolicy Trusted
          Install-Module ps2exe
      - name: Get list of rules
        shell: pwsh
        run: |
          . ps2exe script.ps1

What I get:

Run . ps2exe script.ps1
  . ps2exe script.ps1
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
PS2EXE-GUI v0.5.0.28 by Ingo Karstein, reworked and GUI support by Markus Scholtes

& : The term 'Invoke-ps2exe' 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 line:1 char:2
+ &'Invoke-ps2exe'  -inputFile script.ps1 -nested
+  ~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Invoke-ps2exe:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
Error: Process completed with exit code 1.

"Invoke-ps2exe" is an alias called by ps2exe command that I used. The fact it is able to find the alias means that the module was installed successfully, yet it fails to find it and says: "is not recognized as the name of a cmdlet, function, script file, or operable program. "

Can someone please tell me what I am doing wrong here?

Thanks

user206904
  • 504
  • 4
  • 16
  • 1
    FYI... Understand that the PS2EXE thing is not a real ***.exe***, but just a self-extracting zip file. There is no compiling of .ps* files. Secondly, do to nefarious folks doing this as well, many organizations/enterprises have policies to just block PS2EXE files, and virtually all Anit-Virus solutions will flag them as suspicious. That whole encoding stuff that it does. So, I'd check with your corp security/policy folks to determine if they'd allow this at all. – postanote Jan 04 '23 at 17:48
  • PS2EXE runs in its own process, so might not see your loaded module. Unless you post the actual script there's not much anyone can do to help. – Scepticalist Jan 04 '23 at 19:09
  • @postanote thx for the comment. I know, therefore the `"compile" ` between quotes. And uhh... I don't even work at a company, so that part is not really relevant – user206904 Jan 04 '23 at 20:22
  • @Scepticalist, the actual ps1 script is just `echo ("hello")`. The weird thing is `ps2exe` without any arguments shows the help/usage commands as intended, but when you pass a script it says `...is not recognized as the name of a cmdlet`. But it should be! – user206904 Jan 04 '23 at 20:58
  • @user206904, understood, but people posting are often in an org/ent/edu environment. So, there's that... So, it is relevant to those who are in such venues and stumble across this Q&A. – postanote Jan 04 '23 at 21:35

1 Answers1

2

Ps2exe runs only on ps desktop, not on ps core.

shell: pwsh

Means powershell core. should be replaced with:

shell: powershell

Source: https://github.com/MScholtes/PS2EXE/issues/82

mklement0
  • 382,024
  • 64
  • 607
  • 775
user206904
  • 504
  • 4
  • 16