Using Powershell-Scripts to open all your programs

Do you come to work in the morning and the first thing you do is opening up 5+ programs? And these programs are always the same ones? How about automating a simple task!?

If you answered yes to these three questions I have a life hack for you. – I guess you also need to be on Windows.

Goal

The goal is to have an icon on the Desktop of your machine double-click it and have everything you need open up. Automagically if I dare to say!

Which programs should open? Well that is for you to decide. Whatever it is, even a specific website.

The Tech behind it all

We will be using two key technologies for our little life hack

PowerShell and Batch If you don’t know either of these don’t worry. While I will provide some background information it is just that, if you just want to juice bits – skip ahead.

Quick overview of Batch on Windows

Batch is a term that comes a way to process things. Specifically batch processing – a way of executing something without the possibility of interaction. That means once you start the execution there is no going back. The script will execute until it either throws an error or gets to the end of the script.

Batch files on Windows can be identified by their file extensions: .bat, .cmd or .btm. Essentially they are text files. They contain commands that get executed.

If you want to read a bit more about Batch on Windows or batch processing.

PowerShell-Scripts

PowerShell is similar in function to the Windows Command Prompt (cmd.exe) but different in many ways. For example it has great support for copy/paste via the mouse – something the cmd lags.

One thing that PowerShell is missing though is the ability to double-click to execute. This has some security reasons behind it – mainly so you don’t unknowingly execute a script. But it makes PowerShell harder to use. We want to simplify our workflow and don’t want to copy/paste the code into PowerShell every time.

But we will address this concern.If you want to know more about PowerShell.

Let’s get going

Okay so we will be creating two files one Batch-script and one PowerShell-script. They can be in any folder you want them to be. I prefer to have the Batch-script on the Desktop and the PowerShell-script in some other folder. Just place them wherever is convenient for you.

The PowerShell-Script

First we will start with the PowerShell-script. Open up an editor like Windows-Editor or Visual Studio Code. Let’s start by saving the empty file to your desired folder. Hit Ctrl+S to save the file. Give it a name like testScript.ps1 – don’t forget the .ps1 at the end! In the Windows-Editor make sure to select “All Files” or the file will be saved as a text document and not as a PowerShell-script.

Now we have the basic script ready. Now to the magic: the Start-Process command opens up a program. For example Start-process “chrome”; opens up a new Chrome window. Let’s just try this. Open up PowerShell on your machine and copy paste the command into the window and hit enter. Chrome should now open a new window.

And now for the hard part. You have to decide what programs should open. You can add as many as you like, just make sure to put all of commands into one single line:

Start-process “chrome”;Start-process “chrome”;Start-process “chrome”;

This opens three new Chrome windows.

What you have to put between the quotations marks can be found out by opening the startmenu, right clicking the program you want to call, open properties and copy the Target field.

The Batch-Script

Let’s make a new file, similar to the way we did it before but this time the name has to end in .bat.

Here we have to only add two lines:

The first line is @echo off this hides all the output and just makes your life a bit easier. The second line is bit more complicated let’s see it in full first:

PowerShell.exe -ExecutionPolicy Bypass -Command „& ‚D:\Coding\Powershell-Scripts\FirstBlogPost\startDeveloping.ps1′“

Let’s step through it step by step. First up we have PowerShell.exe this enables us to execute a PowerShell-script. Next up we have a flag: -ExecutionPolicy Bypass, this enables us to execute a PowerShell-script from a Batch-file. And at the end we have the -Command flag with the path to our PowerShell-script we wrote before. So if we put this together open up a PowerShell, open a script and execute it.

If you have any troubles here you can troubleshoot by adding another line to the Batch-file at end with just the command PAUSE.

Going Further

All of this is pretty cool and we already can automate a lot of stuff with just this one function. But to add to this you can give an additional parameter to open for example a specific website.

Start-process “chrome” “https://davidweik.de/”;

Or you can open up an Excel-file by giving the full path + filename as a parameter when opening Excel.

If you are interested in an example code I published something on my GitHub Page.

If you have any questions or suggestion please let me now.

David