Batch Powershell launcher

Windows comes out of the box with Powershell scripts disabled, and asking every user to change their execution policy to allow running them is a hassle. To get around that, I wrote this little batch script snippet that I just prefix to all my Powershell scripts.


START POWERSHELL -COMMAND "(Get-Content """%~f0""").Where({$_ -eq '#POWERSHELL#'},'SkipUntil') | Out-String | Invoke-Expression" & EXIT /B
#POWERSHELL#

#Example PS script...
Get-Command | Out-GridView

Pause

Then I save my file as a .bat. Now I can double click the batch file, which launches in CMD, then starts Powershell, loads the contents of the calling script file, skips to the line that says #POWERSHELL# and passes the rest of the content through to Powershell, and exits the batch file.

This entry was posted in Coding and tagged , , . Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.