PowerShell: Warming Up

So you’ve decided to learn PowerShell? Then we’re on the same boat, you and I!

While I have been playing around with PowerShell for a bit now and for a variety of different purposes, I have yet to sit down and learn the details from the very beginning. PowerShell may have a relatively easy learning curve but relying on your existing knowledge of the .NET Framework will only take you so far.

In this series, I’m going to start the process of learning PowerShell from the ground up, exploring the details that make this great tool such a pleasure to play with.

So what is PowerShell?

At its core, PowerShell is two things:

  • A command-line interface.
  • A scripting language.

Wait, what is a command-line interface?

A command-line interface is a way of interacting with a computer or a program by means of typing text commands. Command-line interfaces are also known as console user interfaces, or sometimes just the console. This is not to be confused with gaming consoles such as the Xbox or PlayStation, though I wonder if someone ever had the nifty idea of making a game that runs on PowerShell.

PowerShell Hello Pumpkin

And what is a scripting language?

A scripting language is a programming language that supports scripts. So what are scripts? Scripts are text files that contain a series of commands written in a given scripting language. That scripting language will have an interpreter that is able to look at the file and run each command one-by-one, following any conditional logic in there. Think of a script as mini-program to achieve a specific end. PowerShell scripts can be used to automate many tasks in the operating system, as well applications that support PowerShell as an interface such as SQL Server.

Where did Command-line interfaces come from?

Command-line interfaces have been around the block. Back in the eighties, when slim cellphones weighed 20 pounds and 64kb was enough for everyone, command-line interfaces were how people talked to computers. There was no Siri or Cortana in those days, so people had to make do with what they had.

One of the most popular command-line interfaces in those wonderful days of hyper-typing was Microsoft Disk Operating System or MS-DOS. The popularity of MS-DOS eventually grew so much that it took over the consumer market almost completely at the time. Soon after MS-DOS was introduced, Microsoft came along with their new Operating System, called Windows. Funny enough though, Windows, when it started, and up to Windows 9x, was merely an application that ran on top of DOS, requiring it for much of its core functionality. A bit like a browser add-on, without the browser.

What about today?

Save for the pleasure of playing retro games on MS-DOS emulators, MS-DOS itself is pretty much gone. Windows now runs on its own NT Kernel and has no need for MS-DOS anymore. However, the command-line interface of MS-DOS has survived the erosion of time in the form the CMD utility in Windows, also known as the Command Prompt. The Command Prompt emulates the behaviour of the MS-DOS interface of old and lets us interact with the computer through issuing direct text commands to it.

Isn’t that enough?

Ironically, CMD ended up being even less powerful than MS-DOS was, powerful being a euphemism here. Some commands were gone – oh security-flawed deltree, how I miss thee – and when it comes to scripting, we still had to resort to writing batch files in an awkward and very limited scripting language, language being another euphemism. There were some attempts at using some other existing scripting languages – such as vbscript and jscript – that would ease management and automation of the operating system, but there were always limitations around every approach.

Where does PowerShell fit in?

While there were prior attempts at replacing the Command Prompt with a more juiced-up command line, it was only with the advent of the .NET Framework that Microsoft gained a really good platform to build upon. PowerShell is built on .NET from the core. Every PowerShell command, variable, result, is some object in .NET, running on the CLR. This means we have full access to the power of the .NET Framework right from the command line itself.

NET Ring Chart With PowerShell

Great! How do I get PowerShell?

You probably already have it. PowerShell has come a long way since it was introduced as Monad in a conference in 2003. It has come pre-installed with major Windows releases since Windows 7 and has been available as a download for others before.

Version Pre-Installed On Download For
PowerShell 1 Windows XP SP2, Windows Server 2003, Windows Vista, Windows Server 2008
PowerShell 2 Windows 7, Windows Server 2008 R2 Windows XP SP3, Windows Server 2003 SP2, Windows Vista SP1
PowerShell 3 Windows 8, Windows Server 2012 Windows 7 SP1, Windows Server 2008 SP1, Windows Server 2008 R2 SP1
PowerShell 4 Windows 8.1, Windows Server 2012 R2 Windows 7 SP1, Windows Server 2008 R2 SP1, Windows Server 2012

If that’s not enough, PowerShell 5 is currently in the making as I write this, the public preview having been made available last April.

How does PowerShell look like?

Commands in PowerShell are called cmdlets, pronounced command-lets. Cmdlets have a distinct look about them, their syntax following a verb/noun pattern that makes them easy to understand and infer the purpose of.

Examples are:

  • Get-Help
  • Get-Command
  • Set-Content
  • Set-Date

There are a number of very common verbs in the names of these cmdlets, such as:

  • Get
  • Set
  • Start
  • Stop
  • Add
  • Remove

Some nouns are also quite common, for example:

  • Help
  • Command
  • Service
  • Computer
  • Location

Having commands that are easy to understand, remember, and even infer if you don’t know them yet, is one of the joys of PowerShell.

Thoughts

So what do you think? Ready to learn some PowerShell? Oh, you’re already learning? That’s great! So what has been your biggest head-scratch until now? Or are you already a PowerShell-Pro? If so, what challenges have you faced that you’d like to share?


Next Pumpkin: Coming Soon…
Pumpkin Index: Learn / PowerShell


Photo by State Farm is licensed under CC BY 2.0

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s