PowerShell: Improved .bat file

Discovery

I found a great article that describes a great .bat file for running a PowerShelll script!

Description

This article by Jacob Zinicola that you can find here gives a step-by-step guid on how he came to his .bat file to run a .ps1 file.
What is very usefull here is that he also has a .bat-script that can execute the PowerShell script using elevated permissions.

The Scripts

I edited Jacob’s script a litle bit to also change the working directory to the location of the script. This was required for one of my scripts.

@ECHO OFF
echo %~dp0
PowerShell.exe -NoProfile -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -Command ""& {cd %~dp0; %~dpn0.ps1}""' -Verb RunAs}"
PAUSE

You can just copy/paste this code into notepad, “Save As” .bat and execute.

Advertisements

Tags: , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: