Wrapping A PowerShell-Script Call In A Batchfile

Wed, Feb 1, 2017 1-minute read

Yet another opinion on this topic, YAY!

As I wasn’t satisfied with the most common solutions out there (first 5 google hits) – I’ve decided to create a .ps1->.bat wrapper on my own:

@echo off
setlocal enableextensions enabledelayedexpansion
set psscript="path_to_your_script"
echo ==================================================
echo ============= WRAP POWERSHELL SCRIPT =============
echo ==================================================

echo calling %psscript% with args %*
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%psscript%' %*"

echo ==================================================

Why did I create another version of the very same thing that should be well known already? – because I wanted to pass all arguments/parameters that are passed to the .bat-File to the wrapped PowerShell script:

editor with example

Update: of course this also works with ‘BoundParameters’ 🙂

example with bound parameters


If you don’t like it – have a look at those alternatives: