Skip to content

Instantly share code, notes, and snippets.

@JonasGroeger
Last active May 26, 2023 11:18
Show Gist options
  • Save JonasGroeger/10417237 to your computer and use it in GitHub Desktop.
Save JonasGroeger/10417237 to your computer and use it in GitHub Desktop.
Generic .bat file to launch .ps1 file with same name in same directory. Example: You have "start.ps1" to do something. Download this Gist and save as "start.bat". The latter will launch "start.ps1" by double-clicking.
@echo off
setlocal
REM Generic .bat file to launch .ps1 files.
REM Name the .bat file like the .ps1 file and you are done.
set this_file_no_extension=%~n0
set ps1_file=%this_file_no_extension%.ps1
powershell.exe -ExecutionPolicy Bypass -NoLogo -Noninteractive -NoProfile -File %ps1_file%
endlocal
@NazmusLabs
Copy link

NazmusLabs commented Sep 15, 2022

This is perfect, thanks. I was looking for a way to easily make a "double-clickable" .ps1 experience.

May Allah (S.W.T.) bestow upon you His Blessings and Guidance. Ameen.

@tberta
Copy link

tberta commented May 26, 2023

I made a custom version myself as I needed argument handling and encountered some problems with the -file and -arguments options.
https://gist.github.com/tberta/3cb709091b94e4a1c91511873bad1270

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment