Windows PowerShell
By: Scott Swigart

UNIX administrators and programmers have long lived in an environment that provides rich scripting support. Conversely, Windows has relied on GUIs to perform administrative tasks. As a result, the barrier to learning Windows administration is low, but automating administrative tasks is substantially more complex on Windows than on UNIX.

More than a decade after releasing its first server OS, Microsoft is finally releasing a powerful scripting shell known as Windows PowerShell. At first glance, PowerShell seems to replicate many typical scripting environments. Through PowerShell, you can execute system commands, which Microsoft calls cmdlets, and pipe the results to other cmdlets. There are also aliases for commands, which gives the impression of a UNIX rip-off. For example, “ls” lists files and “ps” lists processes. But if you dig a bit deeper, you’ll find that PowerShell is fundamentally different.

Shell environments have previously been text-generating and -parsing systems. The output of one command is piped into the next as a string. Text-parsing features comprise a significant portion of the scripting feature set. PowerShell is different. Because it's built on top of the Windows .NET Framework, objects (and not strings) are piped from one cmdlet to the next.

For example, the output from this PowerShell cmdlet

PS C:\> ps explorer

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
   1140      33    41156      61364   195 1,503.41    420 explorer

looks pretty typical for a UNIX “ps” command. However, consider the following:

PS C:\> ps explorer | format-list -property *

__NounName                 : Process
Name                       : explorer
Handles                    : 1140
VM                         : 203956224
WS                         : 62836736
PM                         : 42143744
NPM                        : 34112
Path                       : C:\WINDOWS\Explorer.EXE

This PowerShell cmdlet returns a list of .NET Framework Process objects. By piping those objects to the Format-List cmdlet, you can output each object property and its value. If you want just one specific value, you can use a cmdlet as simple as

PS C:\> (get-process explorer).WorkingSet64
62816256

PowerShell lets you execute any .exe or .cmd files, so your favorite command-line utilities aren't lost. PowerShell also has native knowledge of Windows Management Instrumentation (WMI) through the Get-WmiObject cmdlet. 

Microsoft now has a truly powerful scripting environment that unifies existing command-line utilities, WMI, and the .NET Framework. Even so, it’s highly doubtful that Windows admins will switch over to primarily scripting administrative tasks. Using GUIs is simply too engrained and provides high productivity for discrete operations. That being said, PowerShell opens the door to administrative scripting that even a UNIX admin might envy.