0% found this document useful (0 votes)
2 views

Lab_Module_1

The document provides lab instructions for using Microsoft Windows PowerShell v2, including exercises on searching for text files, browsing the registry, and utilizing the PowerShell pipeline. It covers practical tasks for systems administrators to automate processes and manage services effectively. Each lab section includes specific scenarios, tasks, and expected results to enhance learning and application of PowerShell commands.

Uploaded by

shrikantnpar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lab_Module_1

The document provides lab instructions for using Microsoft Windows PowerShell v2, including exercises on searching for text files, browsing the registry, and utilizing the PowerShell pipeline. It covers practical tasks for systems administrators to automate processes and manage services effectively. Each lab section includes specific scenarios, tasks, and expected results to enhance learning and application of PowerShell commands.

Uploaded by

shrikantnpar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Lab Instructions: Fundamentals for Using

Microsoft® Windows PowerShell® v2


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

ii. Lab B: Using the Windows PowerShell Pipeline


a) Exercise 1: Stopping and Restarting a Windows Service
b) Exercise 2: Exploring Objects Returned by PowerShell Commands
c) Exercise 3: Processing PowerShell Output
Lab A: Using Windows PowerShell As an
Interactive Command-Line Shell
Estimated time: 50 minutes
You work as a systems administrator. You have installed Windows Server 2008 R2 and need to
learn how to automate some tasks. You heard that PowerShell was great for this sort of thing and
need to start learning how to use it. You have used command-line utilities in the past and want to
get started working with PowerShell as quickly as possible. You’re also looking for tips on how
you can discover things in PowerShell on your own.

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.

Before you begin the lab you must:


1. Start the AD virtual machine, and then log on by using the following credentials:
• Username: NEWHORIZONS\administrator
• Password: Passw0rd
2. Open a Windows PowerShell session as Administrator.
3. Open Windows PowerShell and execute the following command:
“These are my notes” | Out-File C:\users\Administrator\Documents\notes.txt
Lab A: Exercise 1: Searching for Text Files

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.

The main tasks for this exercise are as follows:


1. Browse the local file system using familiar command prompt and/or UNIX commands.
2. View the entire contents of one user’s profile folder.
3. View a list of all text files in all users’ document folders.

� 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.

• Create a folder called Test at the root of the C drive.

Hint: What command would you use to make a directory? Use that command to create the new folder.

• Remove the C:\Test folder.


� Task 2: View the entire contents of a folder
• Get the entire list of all files in all folders and subfolders of the user profile folder for the
Administrator account.

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.

� Task 1: View cmdlet help


• View basic help information for the Get-PSDrive cmdlet using Get-Help.
• View full help information for the Get-PSDrive cmdlet using Get-Help with the -Full
parameter.

� Task 2: Navigate the registry


• Show a list of all available PSDrives using the Get-PSDrive cmdlet.
• Change the current location to HKLM:\Software\Microsoft.
• Show a list of all available PSDrives for the Registry provider.
• Change the current location to the HKEY_CURRENT_USER registry hive and list the
contents at the root of that drive.

� Task 3: Create a new PSDrive


• Create a new PSDrive using the New-PSDrive cmdlet. This drive should be named “HKU”
and it should have the HKEY_USERS Registry hive as the root.

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.

The main tasks for this exercise are as follows:


1. Discover commands using aliases and aliases using commands.
2. Learn how to use the help system using Get-Help.
3. Discover new commands with Get-Command.
4. Get current, online help for a command.

� Task 1: Discover commands using aliases and aliases using commands


• Find the command associated with the alias “dir” using Get-Alias.
• Find other aliases for the same command using Get-Alias with the Definition parameter.

� Task 2: Learn how to use the help system using Get-Help


• View basic help information for the Get-Help cmdlet using that cmdlet itself.
• View the examples for Get-Help using the help proxy command.
• Show the full help for Get-Help using the help proxy command.

� Task 3: Discover new commands with Get-Command


• Find all commands with “Service” in their name using Get-Command and wildcards.
• View basic help information for Get-Command using the help command.
• Find all commands of type cmdlet with “Service” in their name using Get- Command,
wildcards and the CommandType parameter.
• Find all commands with the “Service” noun using Get-Command with the Noun parameter.
� Task 4: Get current, online help for a command
• Get the current, online help for the Get-Service cmdlet using the Get-Help cmdlet.

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.

Lab A: Exercise 4: Adding Additional Commands to Your Session Scenario


When working with some Windows components and server products, you must load modules or
snap-ins to be able to access the commands they provide.

The main tasks for this exercise are as follows:


1. Find all “Module” commands.
2. List all modules that are available.
3. Load the ServerManager module into the current session.
4. View all commands included in the ServerManager module.

� Task 1: Find all “Module” commands


• Show all “Module” commands using Get-Command so you know what is used to manage
modules.

� Task 2: List all modules that are available


• List all modules that are available on the current system using Get-Module.

Hint: You can also get a directory listing of the $pshome/modules folder.

� Task 3: Load the ServerManager module into the current session


• View basic help documentation and examples for Import-Module so that you know what
modules are and how to load them.
• Load the ServerManager module into the current session.
� Task 4: View all commands included in the ServerManager module
• Show a list of all commands that are part of the ServerManager module using Get-Command.
• Get a list of the Windows roles and features that are installed or available on the current system
using Get-WindowsFeature.

Results: After this exercise, you should be able to view and load modules into
PowerShell and show what commands they contain.

Lab A: Exercise 5: Learning How to Format Output Scenario


When viewing data in PowerShell, you can format the output to get the results you need.

The main tasks for this exercise are as follows:


1. View the default table format for a command.
2. View the default list and wide formats for a command.

� Task 1: View the default table format for a command


• View a list of all processes whose names start with “w” using the Get-Process command.
• Show the default table view for process objects using the same command but passing the
results to Format-Table.

� 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.

The main tasks for this exercise are as follows:


1. View the Windows Update service details.
2. Determine what would happen if you stopped the Windows Update service.
3. Stop the Windows Update service with confirmation.
4. Restart the Windows Update service.

� Task 1: View the Windows Update service


• Open Windows PowerShell.
• Use the Get-Service cmdlet to view the Windows Update service.

Hint: Do not run Get-Service by itself. Rather, include a parameter so that only the
Windows Update service is returned.

� Task 2: Determine what would happen if you stopped the service


• Use a pipeline to pass the results of your last Get-Service call to the Stop- Service cmdlet with
the WhatIf parameter to see what would happen.

� Task 3: Stop the Windows Update service with confirmation


• Use a pipeline to pass the results of your last Get-Service call to the Stop-
Service cmdlet with the Confirm parameter. When you are prompted press Y
to stop the service.
� Task 4: Restart the Windows Update service
• Use a pipeline to pass the results of your last Get-Service call to the Start-Service cmdlet to
restart the service.

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.

� Task 1: View cmdlet help


• View full help information for the Get-Member cmdlet.

� Task 2: Get visible members for Service objects


• Use Get-Member in a pipeline to show all visible members for Service objects.

� Task 3: Get properties for Service objects


• Use Get-Member in a pipeline to show all properties that are available for Service objects.

� Task 4: Get all members for Service objects


• Use Get-Member in a pipeline to show all members that are available for Service objects.
� Task 5: Find properties by wildcard search and show them in a table
• Get a list of all files and folders (hidden and visible) at the root of the C: drive.
• Show all properties on files and folders that contain the string “Time”.
• Generate a table showing all files and folders at the root of the C: drive with their name,
creation time, last access time and last write time.

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.

Lab B: Exercise 3: Processing PowerShell Output

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.

The main tasks for this exercise are as follows:


1. List all commands that are designed to process output.
2. Show the default output for a command.
3. Send command output to a file.
4. Send command output to a grid and sort and filter the results.

� Task 1: List all commands that are designed to process output


• Show all commands with the verb “Out” in their name.
Hint: The Get-Command cmdlet supports parameters that let you customize its behavior. For example, one
parameter enables you to only retrieve the cmdlets that have a particular verb.

� Task 2: Show the default output for a command


• Review the help information for the Get-EventLog cmdlet including the parameters and the
examples so that you understand how it works.
• Show the 100 most recent events from the System event log of type warning or error in the
default output.

Note: The Get-EventLog cmdlet includes several parameters that can help filter the type of
information that the cmdlet returns.

� Task 3: Send command output to a file


• Pipe the results of the same command you used to get the 100 most recent events from the
System event log of type warning or error to a file using the appropriate “Out” command.

� 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.

You might also like