Lab Answer Key - Module 2 - Working With The Pipeline
Lab Answer Key - Module 2 - Working With The Pipeline
Answer Key: Module 2: Working with the Pipeline
Lab Answer Key: Module 2: Working with the Pipeline
Lab A: Using the Pipeline
Exercise 1: Selecting and Sorting Data
Task 1: Display the current day of the year
1. Log on to the 10961BLONCL1 virtual machine as Adatum\Administrator.
2. To find a command that can display the current date, run:
help *date*
Notice the GetDate command.
3. To display the members of the date object, run:
Get-Date | Get-Member
Notice the DayOfYear property.
4. To display only the day of the year, run:
Task 2: Display information about installed hotfixes.
1. To find a command that can display a list of hotfixes, run:
help *hotfix*
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 1/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline
Notice the GetHotfix command.
2. Run:
Get-Hotfix | Get-Member
This will display the properties of the hotfix object. If needed, run GetHotfix to see
some of the values that typically appear in those properties.
3. To display a list of installed hotfixes, including only specified properties, run:
Task 3: Display a list of available scopes from the DHCP server
1. To find a command that can display DHCP scopes, run:
help *scope*
Notice the GetDHCPServerv4Scope command.
2. To display the command Help, run:
Notice the available parameters.
3. To display a list of scopes, run:
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 2/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline
4. To display a list of scopes that includes only the specified properties, run:
Task 4: Display a sorted list of enabled Windows Firewall rules.
1. To find a command that can display firewall rules, run:
help *rule*
Notice the GetNetFirewallRule command.
2. To display a list of firewall rules, run:
Get-NetFirewallRule
3. To read command Help, run:
4. To display a list of enabled rules, run:
5. To display a list of enabled rules that includes only specified properties, run:
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 3/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline
DisplayName
Task 5: Display a sorted list of network neighbors
1. To find a command that can display network neighbors, run:
help *neighbor*
Notice the GetNetNeighbor command.
2. To read command Help, run:
3. To display the neighbor list, run:
Get-NetNeighbor
4. To display a sorted neighbor list, run:
5. To display a sorted neighbor list that includes only specified properties, run:
Task 6: Display information from the DNS name resolution cache.
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 4/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline
1. To ping LONDC1, run:
ping LON-DC1
2. To ping LONCL1, run:
ping LON-CL1
3. To display a list of commands that use the word cache, run:
help *cache*
Notice the GetDnsClientCache command.
4. To display the DNS cache, run:
Get-DnsClientCache
5. To display the DNS cache and include only specified properties, run:
6. You will notice that the ‘‘Type’’ data doesn’t return what you expect and is raw
numerical data i.e. A, CNAME etc however each number does map directly to a
‘‘Record Type’’ and you can filter for such i.e. 1= A, 5=CNAME etc and you will learn
how to add additional filters later in the module to determine the numbers and
corresponding record types. i.e. GetDNSClientCache | WhereObject type eq 5
returns only CNAME records. You will notice a similar situation for other data returned
such as ‘‘Status’’.
Results: After completing this exercise, you will have produced several custom reports
that contain management information from your environment.
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 5/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline
Lab B: Converting, Exporting, and Importing Objects
Exercise 1: Converting Objects
Task 1: Produce an HTML report listing the processes running on a computer
Note: In this document, long commands are typically displayed on several lines.
Doing so helps prevent an unintended line break in the middle of a command.
However, when you type these commands, you should type them as a single line. That
line may wrap on your screen into multiple lines, but the command will still work.
You should press Enter only after typing the entire command.
1. Log on to the 10961BLONCL1 virtual machine logged in as Adatum\Administrator.
2. To display a list of running processes, run:
Get-Process
3. To display a list of running processes, sorted in reverse alphabetic order by process
name, that shows only the process name, ID, virtual memory, and physical memory
consumption, run:
4. To view the Help for ConvertToHTML, run:
5. To convert the process list to an HTML page, run:
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 6/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline
6. To save the HTML page in a file, run:
Get-Process |
Sort Name -Descending | ConvertTo-HTML –Property Name,ID,VM,PM
|
Out-File ProcReport.html
7. To view the HTML file, run:
Invoke-Expression .\ProcReport.html
8. To create the modified HTML file, run:
Get-Process |
Sort Name -Descending | ConvertTo-HTML –Property Name,ID,VM,PM
–PreContent
"Processes" –PostContent (Get-Date) |
Out-File ProcReport.html
9. To display the HTML file, run:
Invoke-Expression .\ProcReport.html
Results: After completing this exercise, you will have converted objects to different forms
of data.
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 7/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline
Exercise 2: Importing and Exporting Objects
Task 1: Create a commaseparated values (CSV) file listing the most recent 10
entries from the System event log.
Note: When typing these commands, you should type them as a single line, and press
Enter only once, after typing the entire line. However, in the Console application, you
can also type these commands exactly as they are shown. Typically, that means
pressing Enter after each vertical pipe (|) character. If you use this technique, you will
have to press Enter on a blank line, after typing all of the lines, to execute the
command.
1. To display the System event log, run:
2. To convert the log to CSV, run:
3. To export the log as a CSV file, run:
4. To view the CSV file, run:
Notepad SysEvents.csv
5. To export the log and remove the comment line containing type information, run:
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 8/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline
6. To view the revised CSV file, run:
Notepad SysEvents.csv
Task 2: Create an XML file listing services
1. To display a list of services that shows stopped services last, run:
Get-Service |
Sort Status –Descending
2. To export the service list to an XML file, run:
Get-Service |
Sort Status –Descending |
Export-CliXML Services.xml
3. To display the XML file, run:
Notepad Services.xml
4. To choose specified columns to be included in the file, run:
Get-Service |
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 9/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline
5. To display the revised file, run:
Notepad Services.xml
Task 3: Produce a pipedelimited list of the most recent 20 Security event log
entries
1. To view the Help file for ConvertToHTML, run:
2. To display the log entries, run:
3. To display only specified properties of the log entries, run:
4. To export the log entry list as a pipedelimited file, run:
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 10/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline
5. To display the file, run:
Notepad Security.pdd
Task 4: Import data from a pipedelimited file
• To import data from the pipedelimited file, run:
Results: After completing this lab, you will have imported data from and exported data to
external storage.
Lab C: Filtering Objects
Exercise 1: Filtering Objects
Task 1: Display a list of all users in the Users container of Active Directory
1. Log on to the 10961BLONCL1 virtual machine as Adatum\Administrator.
2. To find a command that can list Active Directory® users, run:
help *user*
Notice the GetADUser command.
3. To view the Help for the command, run:
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 11/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline
Notice that the Filter parameter is mandatory. Review the examples for the
command.
4. To display a list of all users, run:
Get-ADUser –Filter *
5. To display a list of all users in a specified container, run:
Task 2: Create a report that shows Security event log entries having the event
ID 4624
1. To display a list of Security event log entries that have the event ID 4624, run:
2. To display the same list, showing only specified properties, run:
3. To convert the list to an HTML file, run:
Select TimeWritten,EventID,Message |
ConvertTo-HTML |
Out-File EventReport.html
4. To view the HTML file, run:
Invoke-Expression .\EventReport.html
Task 3: Display a list of encryption certificates installed on the computer
1. To display a directory listing of all items in the CERT: drive, run:
2. To display the members of the objects, run:
3. To show only the certificates that do not have a private key, run either this:
or this:
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 13/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline
4. To display the list again by using the specified filtering criteria, run:
5. To display the list again by using the specified filtering criteria and showing only the
specified properties, run:
Task 4: Create a report that shows disk volumes that are running low on space
1. To display a list of disk volumes, run:
Get-Volume
If you did not know the command name, you could have run Help *volume* to discover
the command name.
2. To display a list of object members, run:
Get-Volume | Get-Member
Notice the SizeRemaining property.
3. To display only volumes that have more than zero bytes of free space, run:
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 14/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline
Get-Volume |
Where-Object { $PSItem.SizeRemaining -gt 0 }
4. To display only volumes that have less than 99 percent free space, and more than zero
bytes of free space, run:
Get-Volume |
Where-Object { $PSItem.SizeRemaining -gt 0 -and
$PSItem.SizeRemaining / $PSItem.Size
-lt .99 }
5. To display only volumes that have less than 10 percent free space and more than zero
bytes of free space, run:
Get-Volume |
Where-Object { $PSItem.SizeRemaining -gt 0 -and
$PSItem.SizeRemaining / $PSItem.Size
-lt .1 }
This command may not produce any output on your lab computer if the computer has more
than 10 percent free space on all of its volumes.
Task 5: Create a report that displays specified Control Panel items
1. To find a command that can display Control Panel items, run:
help *control*
Notice the GetControlPanelItem command.
2. To display a list of Control Panel items, run:
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 15/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline
Get-ControlPanelItem
3. To display items in the System and Security category, run:
Notice that you do not have to use WhereObject.
Results: After completing this exercise, you will have used filtering to produce lists of
management information that include only specified data and elements.
Lab D: Enumerating Objects
Exercise 1: Enumerating Objects
Task 1: Display a list of key algorithms for all encryption certificates installed
on your computer.
1. To display a list of all items in the CERT: drive, run:
2. To display the members of those objects, run:
Notice the GetKeyAlgorithm() method in the list.
3. To display a list of key algorithms for each installed certificate, run:
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 16/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline
4. To display the same list by using SelectObject, run:
Task 2: Use enumeration to produce 100 random numbers
1. To find a command that can produce random numbers, run:
help *random*
Notice the GetRandom command.
2. To view the Help for the command, run:
Notice the SetSeed parameter.
3. To place 100 numeric objects into the pipeline, run:
1..100
4. To produce 100 random numbers, run:
1..100 |
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 17/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline
Task 3: Execute a method of a Windows Management Instrumentation (WMI)
object
1. Close all applications other than the Windows PowerShell ™ console.
2. Run:
3. To display the members of the object, run:
4. Notice the Reboot() method.
5. To restart the computer, run:
Task 4: To prepare for the next module
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 18/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline
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 written commands that manipulate
multiple objects in the pipeline.
https://skillpipe.com/enGB/Book/BookPrintView/fa8015b274e94be0a2a22064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 19/19