This bash script allows you to run PowerShell commands and scripts in an x64 environment using Docker. It's particularly useful for those using Apple Silicon (or other ARM based systems) who need to run x64-only PowerShell tools.
- Docker installed and running on your system
-
Save the script somewhere on your computer (and optionally add it to your $PATH)
-
Make the script executable:
chmod +x ./pwsh64.sh
- Run PowerShell commands or scripts:
./pwsh64.sh [PowerShell arguments]
- Profit?
Examples:
- Run an interactive PowerShell session:
./pwsh64.sh
- Execute a local PowerShell script:
./pwsh64.sh -File ./path/to/your/script.ps1
- Run a PowerShell command:
./pwsh64.sh -Command "Write-Host 'Hello from PowerShell!'"
The script creates a Docker container using the official PowerShell image for Ubuntu 20.04. It mounts the current working directory to the container, allowing access to local files and scripts. Arguments are passed directly the container so the cli is identical to pwsh
- Only files in the current working directory and its subdirectories are accessible to the PowerShell environment in the container.
- Performance may be somewhat impacted compared to running PowerShell natively on an x64 system.
- Some system-specific operations might not work as expected due to the containerized environment.
- Ensure Docker is installed and running on your system.
- Check that you have internet access if the script needs to download the PowerShell Docker image.
- Verify that your PowerShell scripts and modules are compatible with the PowerShell version used in the container (currently set to 7.2).
MIT