More PowerShell: A Re-Introduction If You’re Starting from Scratch

Any robot knows that robots are for doing things that people don’t want to do. For example, you would never want a robot to go to the rock show for you because you’d want to go yourself. On the otherhand, all this stuff you do everyday that drives you nuts are perfect for a robot and your robot’s favorite tool is probably PowerShell.

The latest versions of Windows gives you PowerShell by default. There’s some goofieness involved if you’re struggling to find it. Our new best friend, Liam, covers that in part here. But let’s just say you can go Start | Programs | Accessories | Windows PowerShell.

Here’s you should find two options: Windows PowerShell and Windows PowerShell ISE.

The latter option here is an integrated script editor. That will become a favorite but first, we need to understand the former option.

Click on Windows PowerShell and you’ll get a blue box.

PowerShell CLI

The Initial PowerShell Command Line Interface

 You can do some pretty cool things here including access the entirety of the PowerShell libraries that are installed. So, you may ask, what is a PowerShell library? Where did I get one or more of those? Am I missing any? I’m so confused.

Well, remember, robot are just like people and the first thing they want to do when they meet an attractive stranger is say “Hello.” If that breaks something, then our relationship was just not to be. We type Hello and hit enter.

Typical Error Message

The Error Message Returned by Unsuitable Command

Well, we are talking to a stranger and seems like he could be a little nicer but at least he is verbose and all in red, presumably to get our attention. Maybe he just didn’t understand. but, instead of going to all the trouble to type “Hello” again, we can just push our up arrow. That will reload our previous command. we hit enter and, no surprise, we get the same  response. And when we do that ten or twelve times, we get get a screen full of repetitive garbage and see our scroll bar moving down the right side of our window.

Here, I’ll give you one for free. Try cls and hit Enter.

Cleared Screen

The Cleared Screen After Running CLS

Ahhh. Sweet clarity.

Note here, now if you tap your up arrow, you get cls again and if you tap it again, you get Hello. This is very clever. In fact, no matter how many commands you’ve entered, tapping up will always give you the previous command. And, as you move back into your command history, you can tap the down arrow of back out of your history.

And just to set your mind at ease here and now and for all time, your commands are NOT case sensitive. Sure HELLO and Hello and hello all generate the same response but you’ll also see that CLS and cls and cLs all clear your screen.

So, let’s tap around until we can run that Hello command one more time and take a closer look. First, it says:

The term ‘hello’ is not recognized as the name of a cmdlet, function, script file, or operable program.

 Okay…

We need to get smarter about what these things are. I’m going to call them “suitable commands.” Obviously, a suitable command is a cmdlet, function, script file or operable program. Let’s start with the last item, an operable program. We know what these are and we have some. For example, we have a program called notepad.exe that lives in c:\windows\system32. So let’s type notepad.exe and hit enter.

Sure enough, Notepad opens.

Also note that while PowerShell opens in c:\windows\system32 and notepad.exe lives in the same folder, you can run a cd.. command twice and your PowerShell will be reading the c:\ root folder. You can run Notepad.exe here and still, Notepad will open. This implies that your PowerShell prompt is able to find the program in this different, remote folder, even if that folder lives on a different path.

Okay, one more robot trick. After you’ve cd.. twice, you can see that you’re in the root C:\ folder. Here, you can type cd pro

A Partially Entered Command

A Partially Entered Command

… and tap your Tab key and our new robot friend will fill in the friggin’ blanks suggesting we’re really trying to type cd program files but just got all lazy human-like.

Type Ahead Code Completion

Type Ahead Code Completion

And it gets even better. Say you’re crazy lazy, here you can just type, n and tap you tab key and our robot friend will give you the first suitable command that starts with the letter “n” …

Type Ahead Code Completion

The First Suitable Command Consistant with Partially Entered Command

In this case, we see, that’s a folder called .\NETGEAR. But we can can cotinue to tap the Tab key and our robot friend will cycle through all the suitable commands in the current folder and all the known paths and offer each of the suitable commands that begin with the letter “n” alphabetically. We can Tab  and Tab until we get to notepad.exe and hit enter and run Notepad.

So lets review:

Up Arrow – Loads previous command consecutively.

CLS – Clears the screen.

CMDLETs are NOT case sensitive.

Command line can open executables.

Command line can read from remote paths and folders.

Tab will try to complete any partially entered command.

That’s a lot for one robot in one day so let’s just plan on looking at those other suitable commands,  next time.

-robot