The How and Why of Learning PowerShell (Part 2 of more than 1)

In my last post in this series I said that you should start learning to use PowerShell now if you haven’t already, but I really didn’t give any reasons why you should. I then went on to talk about how to get started.

In this post I wan to focus a bit more on why I think learning PowerShell is a good thing. I’d like to start this conversation by talking a bit about careers. 

The purpose of a career is to enable people to take care of  fundamental concerns.

We all need to be able to support ourselves, our family, and loved ones. We want to provide shelter, safety, and nourishment for ourselves and the ones we care for.

For those of us that are blessed with a job that we really enjoy, our career can help us meet other needs further up the pyramid. In IT, there is often a lot of creativity and problem solving among other things. (Maybe too much creativity but that is another topic entirely)

The rest of this post is being written with the assumption that the reader acknowledges career as important. So how does PowerShell fit into this whole discussion. Well to start, I have to make one more assumption. Microsoft makes some great products and will continue to have a strong influence in the world of Information Technology. I am not saying they are the only game in town by any means, but I am saying that they have large influential role in IT.

OK, that pretty much does it for assumptions.

What  a career often comes down to is being able to add value to a business. If Person A can do a task in 20 minutes and Person B can do a task in 50 minutes, Person A has the capacity to spend another 30 minutes adding value to the company that  Person B does not have

Person A is the person that has spent the time learning how to effectively use PowerShell. There are a few reasons why scripting and automating can be so powerful.

  • Procedures and tasks become repeatable
  • The results of procedures and task become consistent
  • The number of mistakes is greatly reduced

Microsoft has added PowerShell to its list of Common Engineering Criteria as of the beginning of Microsoft’s 2009 fiscal year. What this means is that all server products that ship from MS must support PowerShell. Now that we are 3/4s of the way through 2010, this is becoming more and more evident. Just off the top of my head here are a few MS server products that support PowerShell.

  • Exchange Server
  • SQL Server
  • Virtual Machine Manager
  • System Center Operations Manager
  • System Center Data Protection Manager
  • Active Directory

There are a bunch more and I haven’t even began to list third party companies that are banking on PowerShell. The list is big and continues to grow every quarter.

Here’s another secret. PowerShell will never completely replace the GUI. Server products are going to have a GUI admin interface forever and a day. This is a good thing! GUIs enable us to understand and learn  new technologies. They help us see what options are available to us and what kinds of things we can do with a particular product. However, we are getting closer to the point in IT in which being able to fuddle through GUIs will be enough. Our peers will be using GUIs to learn how something works and then they are going to use the shell to automate every routine task they can think of. So here’s the question. Do you want to be the person that is creating the routines or the person that executes the routines. Thinking about value for a company and my career, I know which boat I want to be in.

The How and Why of Learning to Use PowerShell (Part 1 of more than 1)

Two years ago, I spent a great deal of time evangelizing PowerShell within my company and publicly as much as possible. Frankly, I felt a little bit like Paul in Athens in Acts 17:32-34.

Some sneered, but others said “We want to hear you again on this subject.” At that, Paul left the Council. A few men became followers Paul and believed.”

Indeed, I did get a few sneers, but mostly what I heard was, “We want to hear more on this subject.” I eventually took that to mean, “This sounds really great but I am not ready for it and it can’t help me solve an immediate problem need right now.”

If that was you one to two years ago, I think its time to check out PowerShell again.

I was listening to the PowerScripting Podcast the other day and Hal and Jonathan were interviewing Don Jones, a well known trainer and PowerShell MVP. During the interview, he brought up a very interesting point that I think was spot on. There are a ton of developers who are PowerShell MVP’s. These people provide a tremendous service to the community, and their input is invaluable. They have brought incredible amounts of additional functionality to PowerShell. Take a look at PowerTab and PowerBoots as just a couple examples.

However, when you go to search on the web for PowerShell,  there is a ton of information that is heavily developer centric that addresses developer oriented problems and solutions. If you are a systems administrator just jumping into PowerShell. Don’t be overwhelmed! It doesn’t have to be that complicated. You don’t have to know how to write code or even script. The only thing you have to be willing to do is work with a command shell and type in commands. That’s all it takes to get started!

PowerShell was created to make the lives of us system admins easier. However, there was a design choice that the PowerShell team made up front that you will have to deal with and overcome. The first 10 minutes of using PowerShell will be a little tough. Just know that it is for the sake of making the next 10 years of your life as an engineer much easier.

Here’s the first thing to know about PowerShell, all of your existing command line tools work as expected. Here I am using ipconfig and some net user commands

image

So that makes life pretty simple when you get started. There are even linux commands that will work. Check out ls or cat if you’ve got a *NIX background.  Things get a little (just a little) bit more tricky when you start using built in PowerShell commands, called “Cmdlets” They are called Cmdlets because they are tiny commands. Think of novels compared to novelettes. This will make more sense as you start to use PowerShell. Basically you can string a set of Cmdlets together to execute a complete command. Cmdlets are the building blocks of functionality in PowerShell.

I will be the first to admit, when I first saw a Cmdlet, I was annoyed. I saw a small stet of Cmdlets like theses:

  • Get-Content
  • Set-Content
  • Get-Serivce
  • Start-Service
  • Get-Process
  • Stop-Process

Here’s what annoyed me. I hated that there was a “-“ in the middle of all the Cmdlets. I remember thinking that it would be hard to type these all the time. I just remember being overwhelmed by the examples I saw and thinking it would be hard to figure out what went where when I was typing in the command shell. However, I didn’t have the context and understanding of how these Cmdlets work so I hope this will help you get over the appearance of complexity.

Cmdlets consist of 2 parts. They all have a verb and a noun. The syntax is “verb – noun” All Cmdlets do something to something. Lets look at Get-Process. This Cmdlet gets (lists/shows/displays) processes that are running on your computer. This brings up another interesting point. Nouns are always singular. This is done for the sake of clarity. There is a Cmdlet called Get-ChildItem. Using plural forms of the word could cause confusion. Do you use –childs or –children? Because PowerShell is used by many people in many countries that speak many languages, the goal is to keep the naming scheme as simple as possible.

The idea here is if you want to look at processes, you know you can use Get-Process. So what if you wanted to look at VMs? You can probably guess that it will be Get-VM. In fact, there is a set of accepted verbs that should be used by people that create Cmdlets. If they have verbs that don’t adhere to the list, you should let them know.

So here’s a couple things to get started. PowerShell comes with the OS in Windows 7. If not, download it from here.

Fire up PowerShell and run some commands like you would in CMD. (See, that wasn’t so bad)

Now try a few cmdlets like Get-Process and Get-Service

Next, there are two Cmdlets that will help you discover all kinds of things.

Get-Help and Get-Command

You can also try using Wildcards.

image

If you are a Systems Engineer working with Windows, its time to start learning PowerShell. What are you waiting for?