PS1 to exe doesn't perform well

Hello,

I have a script which should be running on dozens computers at the first time,
so I need to Set-ExecutionPolicy Unrestricted before I run it. I’ve just added the following line at the top of the script:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force

or:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Confirm:$false

work great within the ISE, nothing happens when converting it to .exe

what I used to convert to .exe:

# import module
Install-Module -Name Sorlov.PowerShell

# export to .exe file
New-SelfHostedPS -SourceFile C:\path\to\file.ps1 -DestinationFile C:\path\to\export.exe -HideConsole -IconPath C:\path\to\icon.ico -Version 2.0.0.0

Admin privileges activated.

please help

I’m not sure about converting to .exe, but you shouldn’t count on ISE as a test environment. The shell inside ISE isn’t the same as the actual PowerShell runtime; rather, it is an emulation of a console packaged inside a GUI app. There are significant differences in the way ISE executes cmdlets and the way PowerShell itself executes them.

On top of that, ISE development has ended. Windows PowerShell v5.1 was the last version supported in ISE, but if your system is up to date you should be using PowerShell Core v7+.

So, you need to test your script either in VSCode or in the shell itself before trying to use it in your production environment. Testing done in ISE is not valid.

Have a look at ISE Steroids. Not free, but I have used it for a long time now to convert to EXE with no issues.

http://www.powertheshell.com/

 

 

Thanks for your reply.

so what tool is the most suggested to create PowerShell scripts now?

I used to work with Visual Studio with the PowerShell extension and looking but it was still not comfortable as the ISE for me

Regardless of all that if you have to change the execution policy in order to run a script you can’t run a script to change the execution policy. You’ll have to change it ahead of time or call powershell executable with -executionpolicy parameter

[quote quote=273906]Regardless of all that if you have to change the execution policy in order to run a script you can’t run a script to change the execution policy. You’ll have to change it ahead of time or call powershell executable with -executionpolicy parameter

[/quote]

yes, that’s the best for me, worked great, thanks!