Securely Creating and Testing .exe Files from .ps1 in Windows Sandbox

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.

  1. Search for "Turn off and on Windows Services" in Start menu

  2. Select "Windows Sandbox" to install, then restart the PC
    Sandbox Windows


  3. 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.

  4. Run a Powershell as Admin

  5. Install-Module ps2exe
    Hint: answer Y first, then answer A

  6. In the same Powershell window, run the following command to enable the script to run:
    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

  7. Write your ps1 script, or copy and paste it here:
    1. Navigate to the file or folder in the host system that you want to share with Windows Sandbox
    2. Right-click the file/folder and select Copy.
    3. Move your mouse cursor into the Windows Sandbox and right-click any blank space
    4. From the menu, select Paste.

  8. 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