PowerShell Re-Introduction: Part Two

Last time we met our new robot friend, the PowerShell Command Line Interface. We learned some cool tricks. We tried to say “Hello” and got a response and started to learn how to talk PowerShellian. We learned that PowerShell really only listens to four things and we called the “Suitable Commands.” They are:

  • Functions
  • Scripts
  • Operable Programs

We looked at that last item, operable programs and we saw how we can run Notepad from our command line.

Now, let’s look at the first, CMDLETs. CMDLETs are the magic of PowerShell. If we’re going to learn anything about CMDLETs we’re going to have to GET some HELP.

That, friends and co-workers, is what Deputy Chief Brenda Lee Johnson (a.k.a. The Closer on TNT) calls a “Clue.”

Get-Help, get-help, Get-Help, gEt-helP, any of those are all the same thing to PowerShell so let’s try it.


The Get-Help CMDLET

Remember this. This is our first cdmlet. Note again that case does not matter. Note also the Verb-Noun format. Every cmdlet employs this format. The verbs are usually something like “get” or “set” while the nouns are any, and I mean any and every, Windows object. Don’t worrry about what this means yet but just remember that when you get the object, you get all of its properties and their values. You also get all of their methods; don’t worry about this yet either.

 Here’s what we “get:”

PowerShell Get-Help

The Get-Help CMDLET Output

I gotta tell you friends, for this robot, this really is the keys to the car; here’s where you can find all you need to know to become the greatest Windows robot ever.

Let’s look at some of these details.

First we get a short description.  Very nice.  Then a long description with syntax and remarks. Hmmm…

Let’s just look at the very first line: get-help <CmdletName>

We we know exactly one cmdlet, Get-Help. Let try it…

Get-Help Get-Help

Help for Get-Help CMDLET

Awesome. Get-Help blah blah blah… But, wait, that’s not all. Look at the Remarks at the bottom. Here, you can get examples, more detailed information or even more technical detailed information. For example, Get-Help Get-Help -full. Here we get a full ten pages of things we can do with Get-Help including:

  • Synopsis
  • Syntax
  • Lengthy Description
  • Parameters
  • Inputs (Not allowed on Get-Help)
  • Outputs
  • Notes
  • Examples (15 in all)
  • Related Links – including a go.microsoft.com link to online help.

At the very end here, while we’re still overwhelmed with all that PowerShell does to make Get-Help work for us, they drop a second jewel on us, Get-Command. Let’s try it.Entering the Get-Command CMDLETPress Enter… Did you see that? Below we can see the last of the output that scrolled by when we ran the Get-Command cmdlet.

Output from Get-Command

The Last Screen of Output from Get-Command

And there you have it, every command that PowerShell can run. Along with the cmdlets, we also get functions and aliases and we’ll look at those later. For example, we can start at the top, we’ve got an Alias % and an Alias ? and a function A: and then another Alias, ac. But then we get the first cmdlet in our list Add-Computer. Let’s Get-Help it:

Get-Help Add-Computer

Running Get-Help Add-ComputerAnd we get: Output from Get-Help Add-Computer

That’s great. We see we can roll into PowerShell and run the Add-Computer cmdlet to add our computer to a domain. We see that we add in parameters for the domain name and the credentials and some other stuff necessary to join a domain. Great.

Help for Add-Computer

Output from Get-Help Add-Computer

All we have to do is learn everything about each of these cmdlets and we know all there is to know about PowerShell, right?

Well, no so fast.

First, by default, we only get the Windows library for the version of Windows we’re running, in my case Win 7. That doesn’t mean there’s not more. Microsoft pretty much publishes a library for every product it sells. And here’s the kicker, the “theory” is that ANYTHING you can do using a Microsoft product’s GUI, you can do in PowerShell; it is intended to be the command line interface for all things Microsoft. We just need to learn how to load those libraries.

Second, we’ve got those other “Suitable Commands” such as functions and scripts. We covered operable programs and we started on cmdlets so, sure, functions and scripts will be coming up next.

Finally, and this is were we might leave you. We’ve mentioned this before and we’re almost done for the day so you’ll have some time to think about what this means. PowerShell is object oriented. What this means is that when you run Get-Something, you actually have an instance of that something in memory with all of it’s properties and methods. Unlike DOS, when you run a command, you got a text string that you had to work with to figure out what it was telling you, in PowerShell, you get the real object. Set a variable to a Get-Something and that variable has all the properties and can run all the methods of every other Something ever created. When we do this, we will chain cmdlets together, called “piping” because you use the pipe character, “|,” to create, read, update and delete any artifact you’ve ever seen in any Microsoft product.

Let’s review.

Get-Help – Why would you start anywhere else?

Get-Command – Displays all the suitable commands you’re currently able to use.

Cmdlets, Functions, Scripts, Operable Programs – All suitable commands.

Libraries – Bundles of cmdlets that support various Microsoft technologies.

Object Oriented – Uses real objects in memory.

Piping – Chain one command to another to build extremely sophisticated solutions.

We’ll be getting more done soon enough.




Comments are closed.