Last active
July 8, 2024 21:06
-
-
Save jpoehls/1469460 to your computer and use it in GitHub Desktop.
Batch file wrapper for a PowerShell script. Wraps execution of a PowerShell script inside a Windows batch file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Execute the PS1 file with the same name as this batch file. | |
set filename=%~d0%~p0%~n0.ps1 | |
if exist "%filename%" ( | |
PowerShell.exe -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Unrestricted -Command "& '%filename%'" | |
:: Collect the exit code from the PowerShell script. | |
set err=%errorlevel% | |
) else ( | |
echo File not found. | |
echo %filename% | |
:: Set our exit code. | |
set err=1 | |
) | |
:: Pause if we need to. | |
if [%1] neq [/nopause] pause | |
:: Exit and pass along our exit code. | |
exit /B %err% |
It doesn't, but you could add %*
to the line with PowerShell.exe -NoProfile
...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! How does your batch script handle command line arguments passed to it?