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. . .
- Gartner Magic Quadrant for Client Management Tools The client management tool market is maturing and evolving to adapt to consumerization, desktop virtualization, and an ongoing need to improve efficiency.
- Audit Ready and Asset Optimized: The Solid Promise of an Intelligent Software Asset Management Solution In this paper Frost & Sullivan examines the benefits of enterprise-grade Software Asset Management solutions, and how these solutions serve as the convergence...
- Pragmatic Endpoint Management: Empowering an SMB Workforce in the Age of Mobility Lacking the time for proper training and education, SMB administrators often resort to taking shortcuts to keep their environment running.This paper discusses the...
- Gartner Magic Quadrant for Application Security The market for application security testing is changing rapidly. Technology trends, such as mobile applications, advanced Web applications and dynamic languages, are forcing...
- LIVE EVENT: 5/7, The End of Data Protection As We Know It. Introducing a Next Generation Data Protection Architecture. Traditional backup is going away, but where does this leave end-users?
- On-demand webinar: "Mobility Mayhem: Balancing BYOD with Enterprise Security" Check out this on-demand webinar to hear Sophos senior security expert John Shier deep dive into how BYOD impacts your enterprise security strategy... All Windows White Papers | Webcasts