Securely Creating and Testing .exe Files from .ps1 in Windows Sandbox
There are many programs that convert a powershell script to an exe file, but converting them to .exe files can be risky with third-party tools often introducing malware.
However, there is a built-in solution for this in Windows, and if you run it in a sandbox, you can even test it without risking the integrity of the host machine.
Here's how we can do this on a Windows 10 machine.
- Search for "Turn off and on Windows Services" in Start menu
- Select "Windows Sandbox" to install, then restart the PC
- Search for "Windows Sandbox" in Start menu, and start it
It will launch a virtual Windows which is perfect for converting an exe file from ps1 script. - Run a Powershell as Admin
Install-Module ps2exe
Hint: answer Y first, then answer A- In the same Powershell window, run the following command to enable the script to run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
- Write your ps1 script, or copy and paste it here:
- Navigate to the file or folder in the host system that you want to share with Windows Sandbox
- Right-click the file/folder and select Copy.
- Move your mouse cursor into the Windows Sandbox and right-click any blank space
- From the menu, select Paste.
- Convert ps1 to exe in Powershell window (run it as admin)
Invoke-ps2exe .\source.ps1 .\target.exe
That's it.
If you found this article useful and would like to show your appreciation, please consider making a small donation via PayPal. Your support will allow me to continue creating valuable content and make my blog even better. Thank you for your contribution!
Comments