Microsoft PowerShell is an operating environment for commands -- cmdlets, functions, filters, scripts, aliases, and executables. PowerShell is based on the .NET Framework, which means that out of the box your existing investment in .NET components is preserved. An additional benefit is PowerShell's extensibility. PowerShell "Snap-ins" let you seamlessly integrate existing .NET components. By eliminating the IDE, PowerShell offers new feedback loops by removing the compile, link, and go steps. Additionally, PowerShell provides new ways to work with cumbersome, long-standing abstractions. For example, instead of launching to a specific area of the registry using regedt32, PowerShell lets you use the dir cmdlet using wildcards on the registry.
To provide rapid development of software solutions, PowerShell pipes objects and provides parameter binding. By reducing the number of lines of code, you realize an enormous benefit during testing and re-factoring for change.
Why Learn PowerShell?
For administrators, PowerShell provides efficient, powerful access to key indicators of the operating system. (It is an abstraction much the way Visual Basic was to the Win32 APIs.) For developers, PowerShell is helpful in SQL scripting or developing DLLs. The concepts and cmdlets of PowerShell offer new ways to work with old information.
Developers need to continually find ways to quickly, effectively, and reliably deliver software solutions. A key element in this process is exchanging higher-level concepts for low-level ones. Consider the following example that demonstrates several concepts.
First, this PowerShell example illustrates the use of the range operation. Second, although no explicit looping or print commands are defined, note that PowerShell iterated and printed the numbers in the range. This is not to say that PowerShell lacks looping constructs (it has foreach, for, do, and while). Rather, it is an example of abstracting away unnecessary details. This is a key idea behind PowerShell.
Here is an example of using ForEach and a glimpse at "piping" with PowerShell.
Note the $_ variable in the previous example. This is an automatic PowerShell variable indicating the current object in the pipeline (variables will be discussed later). In short, PowerShell preserves the looping constructs you are familiar with and provides simpler ways to get things done.
How Does PowerShell Work?
When starting to work with PowerShell, one of the first things you'll use is a cmdlet (pronounced "Command Let"). A cmdlet is a single-feature, built-in command -- a building block by which an operation is completed. For example, one such cmdlet is Get-Date. Note the verb ("Get") and noun ("Date)" are separated by a dash; all cmdlets use this memorable verb-noun form. You can imagine what Get-Date does -- it returns the date. PowerShell also makes use of familiar commands, such as dir. (Digging a bit deeper, you find that dir is a memorable alias for the Get-ChildItem cmdlet.) The cmdlets delivered with PowerShell are covered later.
The runtime performs another role -- information used within the environment is done through structured information: objects with properties. These data objects are compatible with the .NET Framework. Data objects are supplied to and from commands through the pipeline. PowerShell pipes objects and provides parameter binding. This innovation provides rapid development of software solutions for many challenges. Developers are not burdened with creating "plumbing" between cmdlets.
How Does PowerShell compare with .NET?
PowerShell provides features that are accessible and robust. For example, you can create an XML document in a variable based on the contents of an XML file. Refer to the following example:
The task can be completed in a few keystrokes. In contrast, to accomplish the same task in .NET requires several steps and background information: launch the IDE, create a project, know the System.Xml namespace, and use the Load method. Yet even after all those steps, the data has yet to be printed. To print the data requires returning to the IDE, adding more code, compiling, running, and waiting for the results. In PowerShell, you can easily; see the nodes:
Programs help users concentrate and focus by quickly providing user feedback to issued commands. (Inellisense is a good example of employing such "feedback loops.") PowerShell, is a terrific high-speed feedback loop at many levels.