Lab_Module_1
Lab_Module_1
Contents:
i. Lab A: Using Windows PowerShell As an Interactive Command-Line Shell
a) Exercise 1: Searching for Text Files
b) Exercise 2: Browsing the Registry
c) Exercise 3: Discovering Additional Commands and Viewing Help
d) Exercise 4: Adding Additional Commands to Your Session
e) Exercise 5: Learning How to Format Output
Lab Setup
For this lab, you will be browsing the file system and Registry and learning how to use
PowerShell on a domain controller using a domain administrator credential.
Scenario
You are working with another administrator on a Windows Server 2008 R2 domain controller.
The other administrator had been documenting his work in a text file in a user profile, but you’re
not sure which profile has the file. You are taking a colleague’s advice and starting to use
PowerShell to perform tasks you would previously have done with cmd.exe to find the file.
� Task 1: Browse the local file system using familiar command prompt and/or UNIX
commands
• Open Windows PowerShell and set the current location to C:\.
• Show the contents of the C:\users folder from your current location.
Hint: What command would you use to see a directory listing? Read the help for that command and see if it has a
parameter that lets you specify the path of the folder that you want to see a directory listing for.
• Show the contents of the C:\users folder from within that folder.
Hint: What command would you use to change directories? Use that command to change to the C:\Users
folder.
Hint: What command would you use to make a directory? Use that command to create the new folder.
Hint: What command would you use to see a directory listing? Does that command have a parameter that
would enable to you specify the path of the directory you want to see a listing for? Is there a parameter that
would recurse subdirectories?
• Repeat the last activity using the shortest parameter names possible.
Hint: You only need to type enough of a parameter name so that Windows PowerShell can uniquely identify
the parameter you are referring to. “-comp” is often easier to type than “-computername,” for example.
� Task 3: View a list of all text files in all users’ document folders
• Get the list of all text files in all subfolders of all user profile folders.
Hint: You know the command that will list files and folders. Does that command support a parameter that
would enable you to include only certain types of files, such as *.txt?
• Open the notes.txt file in the Administrator account’s documents folder in Notepad.
Results: After this exercise, you should have successfully navigated the file system,discovered
the notes.txt file in the Administrator’s user profile folder, and viewed the contents of that file in
notepad.
Lab A: Exercise 2: Browsing the Registry Scenario
You are working on a shared computer and want to identify differences in startup programs
between different accounts. You must show the different startup programs for the current user
profile and built-in accounts on screen, but you don’t have to actually do the comparison.
The main tasks for this exercise are as follows:
1. View cmdlet help.
2. Navigate the Registry.
3. Create a new PSDrive.
Hint: Read the help to discover the three pieces of information that the New- PSDrive cmdlet needs in order
to create a new drive. The PSProvider for the Registry is called “Registry.”
• View a list of all Registry PSDrives including the HKU drive you just added using the Get-
PSDrive cmdlet.
Lab A: Exercise 3: Discovering Additional Commands and Viewing Help
Scenario
To properly use PowerShell, you need to know how to identify commands, discover new
commands, and get help information to learn how to use commands.
Results: After this exercise, you should know how to discover commands using aliases or
wildcards, how to look up different parts of help information for a command, how to use help
information to learn how to use a command, and how to get current help online.
Hint: You can also get a directory listing of the $pshome/modules folder.
Results: After this exercise, you should be able to view and load modules into
PowerShell and show what commands they contain.
� Task 2: View the default list and wide formats for a command
• Using the same Get-Process command, show the default list view for process objects by
passing the results to Format-List.
• Using the same Get-Process command, show the default wide view for process objects by
passing the results to Format-Wide.
Results: After this exercise, you should be able to show PowerShell output in table, list and wide
formats using default views.
Lab B: Using the Windows PowerShell Pipeline
Estimated time: 30 minutes
You are the server administrator in an enterprise. You have a computer on which you want to
make administrative changes, such as working with Services. Working with those services using
the GUI adds administrative overhead, so you wish to use Windows PowerShell to accomplish
the necessary tasks. To better understand how Windows PowerShell interacts with those
services, you also need to explore the members, properties, and output options for the necessary
commands.
Lab Setup
For this lab, you will be browsing the stopping and restarting services and viewing event log
entries on a domain controller using a domain administrator credential. Before you begin the lab,
you must:
1. Start the AD virtual machine. You do not need to log on, but wait until the boot process is
complete.
2. Start the Windows7 virtual machine, and then log on by using the following credentials:
• Username: NEWHORIZONS\administrator
• Password: Passw0rd
3. Open a Windows PowerShell session as Administrator.
Lab B: Exercise 1: Stopping and Restarting a Windows Service
Scenario
You have used PowerShell to view processes and services on various computers and now you
want to perform some tasks to change the configuration on a computer.
Hint: Do not run Get-Service by itself. Rather, include a parameter so that only the
Windows Update service is returned.
Results: After this exercise, you should have successfully stopped and restarted the Windows
Update service and learned about how the WhatIf and Confirm common parameters can prevent
accidental changes.
Lab B: Exercise 2: Exploring Objects Returned by PowerShell
Commands
Scenario
You are using PowerShell to manage files and services and you know that everything returned
by the commands you use are objects. You want to learn more about the properties and methods
on those objects so that you can use them directly in your work to generate the reports you need.
The main tasks for this exercise are as follows:
1. View cmdlet help.
2. Get visible members for Service objects.
3. Get properties for Service objects.
4. Get all members for Service objects.
5. Get base and adapted or extended members for Service objects.
6. Find properties by wildcard search and show them in a table.
Hint: The Get-Member cmdlet supports several parameters that let you customize the information it
provides.
Results: After this exercise, you should be able to use Get-Member to discover properties and
methods on data returned from PowerShell cmdlets and use that information to format tables
with specific columns.
Scenario
You have used PowerShell to generate output in the PowerShell console, and now you would
like to save the output to a file or work with the output in a Windows dialog so that you can sort
and filter the output to get the results you need.
Note: The Get-EventLog cmdlet includes several parameters that can help filter the type of
information that the cmdlet returns.
� Task 4: Send command output to a grid and sort and filter the results
• Pipe the results of the same command you just used to get event log data to the “Out”
command that displays a grid view.
• Sort the results in the grid by InstanceId in descending order.
• Filter the results in the grid to show only one InstanceId.
Results: After this exercise, you should know how to use PowerShell commands to redirect
output to files or a grid view, and how to sort and filter data in the grid view.