Beta Man

Windows PowerShell: Command Performance

Windows PowerShell is almost ready for prime time.

Microsoft has officially locked Windows PowerShell into Release Candidate status. That means it's pretty much feature-complete and now it's down to bug fixes. Before it's released to the world, let's take another look at this much-ballyhooed new tool and what it can do.

Windows PowerShell
Version Reviewed: RC1
Current Status: RC1
Expected Release: Late 2006
To be perfectly clear, PowerShell (formerly code-named "Monad" and called the Microsoft Shell) is not a new scripting language. It has a scripting language, in much the same way that the old Cmd shell has a batch "scripting" language.

The comparison to Cmd is perfectly appropriate. Like Cmd, PowerShell can run commands interactively. You type the command and it runs right away. You also see the results right away.

PowerShell is actually built as a drop-in replacement for Cmd. It runs all the same command-line tools and has most of the same built-in commands. So you can actually ditch Cmd and start using PowerShell with very few bumps in the road. Of course, PowerShell goes further by providing a host of new cmdlets ("command-lets") that perform various advanced functions.

It's All in the Cmdlets
Cmdlet names all take a standard verb-noun structure, like Get-Wmiobject or Get-Command. There are several commands you can run for more detailed information on what's available:

  • Run Help cmdletname to get instant, detailed help on any command
  • Run Get-Command to see a comprehensive list of cmdlets
  • Run Get-Alias to see a full list of cmdlet aliases (or nicknames)

You'll spot many familiar Cmd commands -- like Move and Type -- in the list of aliases. PowerShell uses these aliases to map familiar Cmd commands to new PowerShell cmdlets.

PowerShell cmdlets also use a standardized syntax. For example, any cmdlet that connects to a remote computer uses the -computer argument to accept the computer name. That standardization makes learning new cmdlets easier than learning full Cmd commands.

Cmdlets are also powerful. Run gwmi Win32_OperatingSystem -co Server1 and you'll be able to determine the operating system and service pack version for a machine named Server1. Gwmi is an alias for the Get-Wmiobject cmdlet and -co is the shortened version of the -computer argument. You only have to type enough letters of the argument name to distinguish it from other arguments within PowerShell.

Through the Pipeline
Like Cmd batch files, PowerShell scripts are basically a series of cmdlets strung together. PowerShell does have a more advanced scripting language, but it still only has a dozen or so constructs for things like If/Then decisions and loops. Consequently, the language is pretty easy to learn.

What's a bit tougher to learn is the pipeline in PowerShell. There was a pipeline in Cmd where you may have, for example, run something like type filename | more. This would execute the type command, send it a filename to display and pipe the output to the more command to display the file's contents one page at a time.

PowerShell works in pretty much the same way. Entering ps | ft will run the Get-Process cmdlet (ps is its alias), and pipe the output to ft (an alias for Format-Table). The result is a formatted list of all processes. Running ps | kill is dangerous, because it takes the output of Get-Process and pipes it to kill (an alias for Stop-Process). This effectively shuts down every process on your machine.

The syntax is pretty straightforward, although it does take a bit of getting used to. Nearly everything is aliased. This honestly makes PowerShell a bit tougher to read, although faster to type. Always keep in mind that nearly anything you're typing is either a cmdlet or an alias. If it doesn't follow the verb-noun format, then it's probably a cmdlet alias.

Getting used to this new tool will give you a leg up on the competition. Once you're familiar with the syntax and structure, you'll be able to work faster and easier.

About the Author

Although Beta Man is anonymous, please feel free to contact him/her about this review or other betas.

Featured

comments powered by Disqus

Subscribe on YouTube