Datasheet
16 CHAPTER 1
•
USING POWERSHELL WITH ACTIVE DIRECTORY
String Cmdlets Together
When used alone, a cmdlet can be a powerful tool. However, you can use
cmdlets more e ciently by stringing multiple cmdlets together using a process
called pipelining. When you pipeline two cmdlets, the results from the rst
cmdlet are fed into the second cmdlet. In order to perform a pipeline, you use
the pipe character (
|
). For example, if you want to kill every Internet Explorer
process running on your computer, you can use the
Get-Process
cmdlet and
pipe its output into the
Stop-Process
cmdlet. e command to accomplish
this looks like this:
Get-Process iexplore | Stop-Process
A pipelined cmdlet is also sometimes referred to as a one-liner. Some advanced
administrators pride themselves on the length of their one-liners. Some
consider a long one-liner that performs a complex task an administrative badge
of honor. One-liners can get complex, but when you start using PowerShell
regularly, they will become second nature. Some of the complex one-liners can
be good substitutes for administrative tasks that require multiple steps. For
example, the following one-liner will look in the Application Event Log, nd
all the error and warning events, put them in a CSV le, and then open the le
with Microso Excel:
Get-EventLog Application -EntryType Error | Export-Csv errors
.csv -NoTypeInformation | Start-Process excel.exe errors.csv
At rst, it may seem complex, but you could easily create a function for this one-
liner, put it in your pro le, and have an easier and more exible way to view your
critical system events. Or imagine running this command on each of your domain
controllers every day using the Task Scheduler and outputting your errors and
warnings into a shared folder.
Get Help on a Cmdlet
You can get help executing any cmdlet by using a special PowerShell cmdlet called
Get-Help
. When you execute
Get-Help
, you must specify the name of the cmdlet
that you want help on as the rst parameter. For example, if you’re stuck on how to
use the
Get-Process
cmdlet, you can run the following command to learn how
to use it:
Get-Help Get-Process
Figure 1.8 shows the output of this command.
c01.indd 16c01.indd 16 5/12/2011 1:07:47 PM5/12/2011 1:07:47 PM










