Computerworld - This article is excerpted from the book Windows 7 and Vista Guide to Scripting, Automation, and Command Line Tools, copyright Pearson Education, all rights reserved. Reprinted with permission.
In 2006, Windows Script Host (WSH) and the Command Prompt shell got a new sibling when Microsoft released a completely new environment called Windows PowerShell. PowerShell has some similarities to the older tools: Like the Command Prompt shell, it lets you type commands interactively as well as put them into script/batch files, and you can easily use pipes and redirection to string files and programs together. Like WSH, it provides a powerful object-oriented programming language for complex scripting.
But PowerShell is a very different, strange animal, and it has powerful features that go way beyond what WSH and the Command Prompt offer. I show you what I mean in the following sections.
An Object-Oriented Command Shell
Here’s one way that that PowerShell is different and strange. Recall that if you type
dir into a regular Command Prompt window, the
dir command spits out a bunch of text onto the screen, giving the names, sizes, and timestamps of the files in a directory. You can direct that text into a file using the
> redirection operator, or you can “pipe” the text to another program using the
| operator. For example, the command
dir /s /b | sort
lists the files in the current directory and its subdirectories as a stream of text, and the text is sent to the sort program that sorts them alphabetically. If you’ve used a command-line environment in nearly any computer operating system in the last, say, 30 years, this should be familiar.
Windows PowerShell command lines appear to work in the same way, but its commands deal with objects rather than just text -- objects that represent files, folders, Windows device drivers, network services, documents any of the hundreds of objects defined in the .NET Framework library). What flows from one command to the next, via that pipe symbol (
|), is a stream of objects. The various PowerShell commands let you generate, manipulate, invoke methods on, change properties of, and extract information from these objects.
As an example, here’s what happens when you type
dir in a PowerShell window. The PowerShell
dir command is actually an alias (shorthand) for the
Get-ChildItem cmdlet. You can type either name and get the same result.
Wait, cmd-what? Cmdlet, pronounced “command-let,” as in “cute tiny little command.” PowerShell’s built-in commands are called cmdlets. Maybe they were out of vowels up in Redmond that year? No, the reason for the odd name is that they’re not completely built in to PowerShell, like cmd.exe’s commands, nor are they really completely independent of it, like exe files. They’re implemented in a new way, so they needed a new word. In any case. . .
- 15 Non-Certified IT Skills Growing in Demand
- How 19 Tech Titans Target Healthcare
- Twitter Suffering From Growing Pains (and Facebook Comparisons)
- Agile Comes to Data Integration
- Slideshow: 7 security mistakes people make with their mobile device
- iOS vs. Android: Which is more secure?
- 11 sure signs you've been hacked
- Taking Windows Mobile on Any Device Taking Windows applications mobile has many advantages, but the process of identifying a solution is complex. Learn how to solve this complex problem...
- Pay-as-you-Grow Data Protection: IBM Tivoli's Full-featured Data Protection Suite for Small to Medium Businesses IBM Tivoli Storage Manager Suite for Unified Recovery gives small and medium businesses the opportunity to start out with only the individual solutions...
- Streamline Data Protection with IBM Tivoli Storage Manager Operations Center IBM Tivoli Storage Manager (TSM) has been an industry-standard data protection solution for two decades. But, where most competitors focus exclusively on Backup...
- Simplify and Consolidate Data Protection for Better Business Results Learn about IBM® Tivoli® Storage Manager Operations Center, which provides advanced visualization, built-in analytics and integrated workflow automation features that leapfrog traditional backup...
- Meg Whitman presents Unlocking IT with Big Data During this Web Event you will hear Meg Whitman, President and CEO, HP discuss HAVEn - the #1 Big Data platform, as well...
- The New Way to Work Knowledge Vault This Knowledge Vault focuses on how, in today's increasingly virtual world, it's more important than ever to engage deeply with employees, suppliers, partners,... All Windows White Papers | Webcasts