1.7. What You Get in PowerShell
On the surface, PowerShell simply appears to be a new command shell, but you get a highly flexible scripting language with it, too. The following sections describe aspects of the PowerShell package and provide some simple examples of how you can use it.
1.7.1. Interactive Command Shell
As I showed you earlier in the chapter, PowerShell comes complete with a range of commands, called cmdlets, that you can use interactively. By combining these commands in pipelines, you can filter, sort, and group objects. Pipelines are a way of combining commands. They have the general form:
command1 | command2
where each step of the pipeline may contain a PowerShell cmdlet, often using multiple parameters. The | character is used to separate the steps of a pipeline. A pipeline can be of arbitrary length.
In the rest of this book, I demonstrate some of the neat tricks you can use to take advantage of pipelines to manage your system.
The following command is a three-step pipeline that retrieves information about running processes, sorts it by process name, and displays selected parts of the results in a table.
get-process svchost | sort-object ProcessName | format-table ProcessName, Handlecount
As you can see in Figure 1-16, you can type the pipeline on a single line. In this book, I will generally present multistep pipelines on multiple lines, since that makes it easier for you to see what each step of the pipeline is doing.
Figure 1.16. Figure 1-16
If you prefer, ...
Get Professional Windows® PowerShell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.