How to run PowerShell by double-clicking

How to do it for Windows/macOS respectively

For Windows

Prepare the following two files.

Double click on the bat file to run the PowerShell script.

Files to prepare

  • Execute.bat
  • script.ps1

Contents of the batch file

By writing “pushd %~dp0” at the beginning of the batch file,
the script path can be written as a relative path.

Execute.bat

pushd %~dp0
powershell -NoProfile -ExecutionPolicy RemoteSigned ".\script.ps1"

For macOS

Prepare the following two files.
Double-click on the command file to execute the PowerShell script.

Files to prepare

  • Execute.command
  • script.ps1

Contents of the command file

By writing “cd `dirname $0`” at the beginning of the command file, you can describe the script path as a relative path.
The path to the script can be written as a relative path.

Execute.command

cd `dirname $0`
pwsh -NoProfile -ExecutionPolicy RemoteSigned "./script.ps1"