What is the best “free” way to compile PS1 files to EXE. I have read that there’s something in the community extensions and also in PowerGUI Pro but I do not want to pay for that if I don’t have to. I downloaded the PSCX but it’s an MSI package and I’m having trouble getting it to install.
I can delete and re download that but has anyone used it? Are there better “free” recommendations for compiling to EXE?
What Don said. Anything that claims to be “compiling” a script is really just creating a self-extracting zip file, or something very similar.
I’ve done that with PowerGUI at client’s request, a couple of times. It makes some things really annoying; for example, if you have code to check the script’s current directory ($PSScriptRoot , $MyInvocation.MyCommand.Path , etc), it’ll start referring to a temporary folder instead of the folder where the .exe file was located.
I have read that and I am OK with that fact. Just being an EXE might help me work around another issue I’m having. I don’t mind that it’s just wrapped up into an EXE.
I am forced to use an API to run my scripts through a non Microsoft RBA and orchestration system.
PowerGUI should do the trick, then. One thing to keep in mind is that if you need to pass parameters to your script and it’s compiled to an EXE by PowerGUI, you need to stick an extra parameter in there (-Arguments, if I remember right), ie:
<div class="d4p-bbp-quote-title">Dave Wyatt wrote:</div>What Don said. Anything that claims to be “compiling” a script is really just creating a self-extracting zip file, or something very similar.
I’ve done that with PowerGUI at client’s request, a couple of times. It makes some things really annoying; for example, if you have code to check the script’s current directory ($PSScriptRoot , $MyInvocation.MyCommand.Path , etc), it’ll start referring to a temporary folder instead of the folder where the .exe file was located.
Did you ever find a way around this problem? I’m having the same issue and don’t like the idea of hard coding a path in.
I have the same issue, .exe is referring to a temporary folder. So you could you please explain the work around. I didn’t understand - I have been struggling with this from a number of days. I am so glad I found this blog.
[System.AppDomain]::CurrentDomain.BaseDirectory will refer to the location of the executable that is running. Normally that’s the $pshome folder (where PowerShell.exe and PowerShell_ISE.exe are located), but when you are using a compiled script generated by PowerGUI, [System.AppDomain]::CurrentDomain.BaseDirectory refers to the folder where the exe is found instead.
It gets the parent process of the Powershell executed by the script, this parent process is the EXE file.
The $ProcessPath is the path of your EXE file.