Professional Documents
Culture Documents
Answer Key: Module 3: Understanding How the Pipeline Works
Lab Answer Key: Module 3: Understanding How the
Pipeline Works
Lab: Working with Pipeline Parameter Binding
Exercise 1: Predicting Pipeline Behavior
Task 1: Review existing commands
For these tasks, you may run individual commands and GetMember to see what kinds of
objects the commands produce. You may also view the Help for any of these commands.
However, do not run the whole command shown. If you do run the whole command, it may
produce an error. The error does not mean the command is written incorrectly.
1. This command is intended to list the services that are running on every computer in the
domain:
Will the command achieve the goal?
No. GetService does not accept ADComputer objects from the pipeline.
2. This command is intended to list the services that are running on every computer in the
domain:
Will the command achieve the goal?
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=17&AnnotationFilterOwn=true 1/5
18/5/2017 Lab Answer Key: Module 3: Understanding How the Pipeline Works
Yes. The ComputerName parameter accepts pipeline input by using
ByPropertyName.
3. This command is intended to query an object from every computer in the domain:
Get-ADComputer –Filter * |
Select @{n='ComputerName';e={$PSItem.Name}} | Get-WmiObject –
Class Win32_BIOS
Will the command achieve the goal?
No. The ComputerName parameter of GetWmiObject does not accept pipeline
input.
4. The file Names.txt lists one computer name per line.
This command is intended to list the services that are running on every computer that is
listed in Names.txt.
Get-Content Names.txt |
Get-Service
Will the command achieve the goal?
No. Pipeline input of the type String will attach to the Name parameter of Get
Service by using ByValue. The ComputerName parameter does not accept pipeline
input by using ByValue.
5. The file Names.txt lists one computer name per line.
This command is intended to list the services that are running on every computer that is
listed in Names.txt.
Will the command achieve the goal?
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=17&AnnotationFilterOwn=true 2/5
18/5/2017 Lab Answer Key: Module 3: Understanding How the Pipeline Works
Yes. GetContent produces objects of the type String, and the ComputerName
parameter can accept those objects.
6. This command is intended to list the services that are running on every computer in the
domain:
Will the command achieve the goal?
No. The ComputerName parameter cannot accept objects of the type ADComputer.
7. This command is intended to list the Security event log entries from every computer in
the domain:
Will the command achieve the goal?
Yes. The parenthetical command produces objects of the type String that are computer
names. Those are accepted by the ComputerName parameter.
Task 2: Write new commands that perform specified tasks
In each of these tasks, you are asked to write a command that achieves a specified goal. Do
not run these commands. Write them on paper.
You may run individual commands and pipe their output to GetMember to see what objects
those commands produce. You may also read the Help for any command.
1. Write a command displays the most recent 50 System event log entries from each
computer in the domain.
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=17&AnnotationFilterOwn=true 3/5
18/5/2017 Lab Answer Key: Module 3: Understanding How the Pipeline Works
Because GetEventLog does not accept pipeline input for its ComputerName
parameter, you have to write this command:
2. You have a text file that is named Names.txt that contains one computer name per line.
Write a command that uses RestartComputer to restart each computer that is listed in
the file. Do not use a parenthetical command.
Because the ComputerName parameter of RestartComputer accepts pipeline input
by using ByValue, the following command will achieve the goal:
Get-Content Names.txt |
Restart-Computer
3. You have a file that is named Names.txt that contains one computer name per line. Write
a command that uses TestConnection to test the connectivity to each computer that is
listed in the file.
The ComputerName parameter of TestConnection accepts pipeline input only by
using ByPropertyName. The objects produced by GetContent do not have a property
named ComputerName, nor do they have an existing property that can be renamed to
ComputerName. Therefore, you must use a parenthetical command:
4. Write a command that uses SetService to set the start type of the WinRM service to
Auto on every computer in the domain. Do not use a parenthetical command.
Because the ComputerName parameter of SetService accepts pipeline input by using
ByPropertyName, you can write the following command:
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=17&AnnotationFilterOwn=true 4/5
18/5/2017 Lab Answer Key: Module 3: Understanding How the Pipeline Works
Get-ADComputer –filter * |
Select-Object @{n='ComputerName';e={$PSItem.Name}} |
Set-Service –Name WinRM –StartupType Auto
You must use SelectObject because the ADComputer objects have a Name property, not a
ComputerName property.
Task 3: To prepare for the next module
When you have finished the lab, revert the virtual machines to their initial state. To do this,
perform the following steps:
1. On the host computer, start HyperV Manager.
2. In the Virtual Machines list, right click 10961BLONDC1, and then click Revert.
3. In the Revert Virtual Machine dialog box, click Revert.
4. Repeat steps 2 and 3 for 10961BLONCL1.
Results: After completing this exercise, you will have reviewed and written several
Windows PowerShell ™ commands.
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=17&AnnotationFilterOwn=true 5/5