You are on page 1of 19

18/5/2017 Lab 

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 10961B­LON­CL1 virtual machine as Adatum\Administrator.

2. To find a command that can display the current date, run:

help *date*

Notice the Get­Date 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:

Get-Date | Select-Object –Property DayOfYear

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/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 1/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline

Notice the Get­Hotfix command.

2. Run:

Get-Hotfix | Get-Member

This will display the properties of the hotfix object. If needed, run Get­Hotfix 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:

Get-Hotfix | Select-Object –Property


HotFixID,InstalledOn,InstalledBy

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 Get­DHCPServerv4Scope command.

2. To display the command Help, run:

Help Get-DHCPServerv4Scope –ShowWindow

Notice the available parameters.

3. To display a list of scopes, run:

Get-DHCPServerv4Scope –ComputerName LON-DC1

https://skillpipe.com/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?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:

Get-DHCPServerv4Scope –ComputerName LON-DC1 | Select-Object –


Property
ScopeId,SubnetMask,Name

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 Get­NetFirewallRule command.

2. To display a list of firewall rules, run:

Get-NetFirewallRule

3. To read command Help, run:

Help Get-NetFirewallRule –ShowWindow

4. To display a list of enabled rules, run:

Get-NetFirewallRule –Enabled True

5. To display a list of enabled rules that includes only specified properties, run:

Get-NetFirewallRule –Enabled True | Select-Object –Property


DisplayName,Profile,Direction,Action | Sort-Object –Property

https://skillpipe.com/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?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 Get­NetNeighbor command.

2. To read command Help, run:

help Get-NetNeighbor –ShowWindow

3. To display the neighbor list, run:

Get-NetNeighbor

4. To display a sorted neighbor list, run:

Get-NetNeighbor | Sort-Object –Property State

5. To display a sorted neighbor list that includes only specified properties, run:

Get-NetNeighbor | Sort-Object –Property State | Select-Object


–Property
IPAddress,State

Task 6: Display information from the DNS name resolution cache.
https://skillpipe.com/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 4/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline

1. To ping LON­DC1, run:

ping LON-DC1

2. To ping LON­CL1, run:

ping LON-CL1

3. To display a list of commands that use the word cache, run:

help *cache*

Notice the Get­DnsClientCache command.

4. To display the DNS cache, run:

Get-DnsClientCache

5. To display the DNS cache and include only specified properties, run:

Get-DnsClientCache | Sort Name | Select Name,Type,TimeToLive

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. Get­DNSClientCache | Where­Object 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/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?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 10961B­LON­CL1 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:

Get-Process | Sort Name -Descending | Select Name,ID,VM,PM

4. To view the Help for ConvertTo­HTML, run:

help ConvertTo-HTML –ShowWindow

5. To convert the process list to an HTML page, run:

https://skillpipe.com/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 6/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline

Get-Process | Sort Name -Descending | ConvertTo-HTML –Property


Name,ID,VM,PM

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/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?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 comma­separated 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:

Get-EventLog –Newest 10 –LogName System

2. To convert the log to CSV, run:

Get-EventLog –Newest 10 –LogName System |


ConvertTo-CSV

3. To export the log as a CSV file, run:

Get-EventLog –Newest 10 –LogName System |


Export-Csv SysEvents.csv

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/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 8/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline

Get-EventLog –Newest 10 –LogName System |


Export-Csv SysEvents.csv –NoTypeInformation

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/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 9/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline

Sort Status –Descending |


Select Name,DisplayName,Status | Export-CliXML Services.xml

5. To display the revised file, run:

Notepad Services.xml

Task 3: Produce a pipe­delimited list of the most recent 20 Security event log
entries

1. To view the Help file for ConvertTo­HTML, run:

Help ConvertTo-CSV -ShowWindow

2. To display the log entries, run:

Get-EventLog –newest 20 –LogName Security

3. To display only specified properties of the log entries, run:

Get-EventLog –newest 20 –LogName Security |


Select EventID,TimeWritten,Message

4. To export the log entry list as a pipe­delimited file, run:

Get-EventLog –newest 20 –LogName Security |


Select EventID,TimeWritten,Message |
Export-CSV Security.pdd –Delimiter '|'

https://skillpipe.com/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?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 pipe­delimited file

• To import data from the pipe­delimited file, run:

Import-Csv Security.pdd –Delimiter '|' |


Select –First 10

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 10961B­LON­CL1 virtual machine as Adatum\Administrator.

2. To find a command that can list Active Directory® users, run:

help *user*

Notice the Get­ADUser command.

3. To view the Help for the command, run:

https://skillpipe.com/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 11/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline

help Get-ADUser –ShowWindow

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:

Get-ADUser –Filter * -SearchBase "cn=Users,dc=Adatum,dc=com"

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:

Get-EventLog -LogName Security |


Where EventID -eq 4624

2. To display the same list, showing only specified properties, run:

Get-EventLog -LogName Security |


Where EventID -eq 4624 |
Select TimeWritten,EventID,Message

3. To convert the list to an HTML file, run:

Get-EventLog -LogName Security |


Where EventID -eq 4624 |
https://skillpipe.com/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 12/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline

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:

Get-ChildItem -Path CERT: -Recurse

2. To display the members of the objects, run:

Get-ChildItem -Path CERT: -Recurse |


Get-Member

3. To show only the certificates that do not have a private key, run either this:

Get-ChildItem -Path CERT: -Recurse |


Where HasPrivateKey -eq $False

or this:

Get-ChildItem -Path CERT: -Recurse |


Where { $PSItem.HasPrivateKey -eq $False }

https://skillpipe.com/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?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:

Get-ChildItem -Path CERT: -Recurse |


Where { $PSItem.HasPrivateKey -eq $False -and $PSItem.NotAfter
-gt (Get-Date) -and
$PSItem.NotBefore -lt (Get-Date) }

5. To display the list again by using the specified filtering criteria and showing only the
specified properties, run:

Get-ChildItem -Path CERT: -Recurse |


Where { $PSItem.HasPrivateKey -eq $False -and $PSItem.NotAfter
-gt (Get-Date) -and
$PSItem.NotBefore -lt (Get-Date) } |
Select Issuer,NotBefore,NotAfter

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/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?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 Get­ControlPanelItem command.

2. To display a list of Control Panel items, run:
https://skillpipe.com/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?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:

Get-ControlPanelItem –Category 'System and Security'

Notice that you do not have to use Where­Object.

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:

Get-ChildItem -Path CERT: -Recurse

2. To display the members of those objects, run:

Get-ChildItem -Path CERT: -Recurse | Get-Member

Notice the GetKeyAlgorithm() method in the list.

3. To display a list of key algorithms for each installed certificate, run:
https://skillpipe.com/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 16/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline

Get-ChildItem -Path CERT: -Recurse |


ForEach GetKeyAlgorithm

4. To display the same list by using Select­Object, run:

Get-ChildItem -Path CERT: -Recurse |


Select Issuer,@{n='KeyAlgorithm';e=
{$PSItem.GetKeyAlgorithm()}}

Task 2: Use enumeration to produce 100 random numbers

1. To find a command that can produce random numbers, run:

help *random*

Notice the Get­Random command.

2. To view the Help for the command, run:

help Get-Random –ShowWindow

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/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 17/19
18/5/2017 Lab Answer Key: Module 2: Working with the Pipeline

ForEach { Get-Random –SetSeed $PSItem }

Task 3: Execute a method of a Windows Management Instrumentation (WMI)
object

1. Close all applications other than the Windows PowerShell ™ console.

2. Run:

Get-WmiObject –Class Win32_OperatingSystem -


EnableAllPrivileges

3. To display the members of the object, run:

Get-WmiObject –Class Win32_OperatingSystem -


EnableAllPrivileges |
Get-Member

4. Notice the Reboot() method.

5. To restart the computer, run:

Get-WmiObject –Class Win32_OperatingSystem -


EnableAllPrivileges |
ForEach Reboot

Task 4: To prepare for the next module

https://skillpipe.com/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?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 Hyper­V Manager.

2. In the Virtual Machines list, right click 10961B­LON­DC1, and then click Revert.

3. In the Revert Virtual Machine dialog box, click Revert.

4. Repeat steps 2 and 3 for 10961B­LON­CL1.

Results: After completing this exercise, you will have written commands that manipulate
multiple objects in the pipeline.

https://skillpipe.com/en­GB/Book/BookPrintView/fa8015b2­74e9­4be0­a2a2­2064dd96fa54?ChapterNumber=16&AnnotationFilterOwn=true 19/19

You might also like