PowerShell – command line interface on steroids

Some of you were born with a cell phone in your hand.  Others like me got their first exposure to computers and technology with the release of the 8088 processor and floppy drives.

Those of us who have gone through the gauntlet of PC technology have also been exposed to the OS cycle of MS-DOS, Windows 3.X, and finally Windows 95 and NT, the precursors of the modern Windows operating systems.  We were fortunate enough to have to use MS-DOS and became intimately familiar with the Command Line Interface (CLI) where you have to type out commands and not have the convenience of flashy Graphical User Interfaces (GUIs).  To this day all Windows operating systems have a command prompt shell where you can use some of the long standing tools to manipulate the file system and perform troubleshooting tasks like sending email, connecting to ftp, and checking connectivity, just to name a few.

While it sounds like there are a lot of tasks that you can perform through the command prompt, the available commands are actually quite limited as far as interacting with the operating system.  Along came VBScript, a scripting language based on Visual Basic using the Component Object Model (COM) to access elements of the running operating system.  This was a big step forward allowing access to more features of the operating system through scripts that could be run on demand or easily scheduled through task scheduler.

In 2006 Microsoft released PowerShell, what I like to call a CLI on steroids.  It is built on top of the .Net Framework.  Through the PowerShell command line interface you can access built-in cmdlets.  These specialized commands implement specific functions enabling you to get the most out of PowerShell with a minimal amount of coding involved.  The real foundation of PowerShell is the use of these built-in cmdlets.  Cmdlets use a verb-noun pair as the naming convention so for the cmdlet get-command, the verb is get, meaning that you are retrieving information, and the noun command signifies that what you are getting is a list of commands.

The first version of PowerShell came with approximately 129 cmdlets and was included with Windows 2003 and Vista.  With the release of Windows 2008 came PowerShell 2.  It included more than 229 cmdlets.  Any function that you wanted to accomplish outside the boundary of these cmdlets would have to be written by you or could be accessed through third party modules that you could import into PowerShell as needed.  This made PowerShell a valuable tool for Windows administrators.

With the release of Windows 2012 last month, PowerShell 3 was also released.  It is available as an optional installation for Windows 2008 SP1 and Windows 2008 R2 SP1.  The power of this new release can be seen with the inclusion of more than 2,200 cmdlets.

With all of this information available there are remarkable only a few commands that you really need to memorize to get started with PowerShell.  The first is get-command.  If you type that in the PowerShell CLI it will list all of the commands that are available to you.  Looking through the results you will see that this list includes cmdlets, aliases, and functions.  You will recognize a lot of the aliases as former command line commands that work with PowerShell just like they did in a command prompt window.

One example of this is dir.  If you type that in a command prompt it gives you the directory listing of the current directory.  It conveniently does the same thing in PowerShell because it is an alias.  Looking at the Alias in the get-command results you see that it is the same as Get-ChildItem.  Typing either one in the PowerShell CLI will return the same results.

A second cmdlet that you need to know is get-help.  Entering it by itself gives you a good amount of information including the syntax of the command as well as examples and additional information on how to use it.  Entering get-help get-command will give you help on the get-command cmdlet.

While I have only scratched the surface of PowerShell, I provided you with some helpful background information as well as some simple information to get you started using PowerShell.  Stay tuned to my blog as I provide PowerShell scripts that will be helpful in managing your IIS and Windows infrastructure.

Some great PowerShell resources are:
http://powershell.org/wp/home/
http://technet.microsoft.com/en-us/scriptcenter

Rick is a Senior Support Lead at OrcsWeb, a hosted server company providing managed hosting solutions.

No Comments