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

Lab_Module_3

The document provides lab instructions for using Core Windows PowerShell Cmdlets, structured into three main modules: Lab A focuses on using core cmdlets for sorting, selecting, and saving objects; Lab B emphasizes filtering and enumerating objects in the pipeline; and Lab C covers advanced pipeline parameter binding for managing Active Directory users and computers. Each lab includes specific exercises with scenarios, tasks, and expected results to enhance practical understanding of PowerShell functionalities. The labs are designed for system administrators to improve their skills in performance monitoring and capacity management using PowerShell.

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_3

The document provides lab instructions for using Core Windows PowerShell Cmdlets, structured into three main modules: Lab A focuses on using core cmdlets for sorting, selecting, and saving objects; Lab B emphasizes filtering and enumerating objects in the pipeline; and Lab C covers advanced pipeline parameter binding for managing Active Directory users and computers. Each lab includes specific exercises with scenarios, tasks, and expected results to enhance practical understanding of PowerShell functionalities. The labs are designed for system administrators to improve their skills in performance monitoring and capacity management using PowerShell.

Uploaded by

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

Lab Instructions: Core Windows PowerShell® Cmdlets

Module 3

Contents:
i. Lab A: Using the Core Cmdlets
a) Exercise 1: Sorting and Selecting Objects
b) Exercise 2: Retrieving a Number of Objects and Saving to a File
c) Exercise 3: Comparing Objects Using XML
d) Exercise 4: Saving Objects to a CSV File
e) Exercise 5: Measuring a Collection of Objects

ii. Lab B: Filtering and Enumerating Objects in the Pipeline


a) Exercise 1: Comparing Numbers (Integer Objects)
b) Exercise 2: Comparing String Objects
c) Exercise 3: Retrieving Processes from a Computer
d) Exercise 4: Retrieving Services from a Computer
e) Exercise 5: Iterating Through a List of Objects

iii. Lab C: Using Pipeline Parameter Binding


a) Exercise 1: Using Advanced Pipeline Features
b) Exercise 2: Working with Multiple Computers
c) Exercise 3: Stopping a List of Processes
d) Exercise 4: Binding Properties to Parameters
Lab A: Using the Core Cmdlets
Estimated time: 30 minutes
You work as a system administrator in a small company. The company you work with has not
invested in an enterprise-class monitoring solution. As a result, you have to do a lot of
performance monitoring and capacity management/trending. One of your duties is to log in to
servers and gather some basic statistics, which you do on an almost daily basis. You would like
to keep a record of their current status by saving a file locally on the server as a future reference.

Lab Setup
For this lab, you will use the available virtual machine environment. Before you begin the lab,
you must:
1. Start the AD, WINDOWS7 virtual machines, and then log on by using the following
credentials:
• Username: NEWHORIZONS\administrator
• Password: Passw0rd
2. Disable the Windows Firewall on AD, WINDOWS7 You can do this from Start | Control
Panel | Windows Firewall. There, click the link to Turn Windows Firewall on or off, and
Turn off the Windows
Firewall for all network locations.

Note: This is not security best practice and under no circumstances should this be done in a
production environment. Using Windows PowerShell doesn’t necessarily require the Windows
Firewall to be completely disabled. However, purely for the learning purposes of this class, we
will disable the firewall on all machines for all labs in order to focus our attentions on
PowerShell as opposed to firewall configurations to get a better understanding of the powershell
concepts involved.
Lab A: Exercise 1: Sorting and Selecting Objects

Scenario
You often check the status of processes on your server and would like to sort the processes so
you can easily view their status.
The main tasks for this exercise are carried out on WINDOWS7 and are as follows
1. Retrieve a list of processes.
2. Sort a list of processes.
3. Select a certain number of processes.

� Task 1: Retrieve a list of processes


• Open Windows PowerShell and retrieve a list of running processes.

� Task 2: Sort a list of processes


• Retrieve a list of running processes and sort them.

� Task 3: Select a certain number of processes


• Retrieve a list of running processes, sort them, and select only the first five.

Results: After this exercise, you will have retrieved a list of first 5 services sorted alphabetically
by their service name.
Lab A: Exercise 2: Retrieving a Number of Objects and Saving to a File

Scenario
You are currently having problems with an application, and want to check for the last five events
in the Windows Application event log.
The main tasks for this exercise are carried out on WINDOWS7 and are as follows
1. Retrieve a list of event logs.
2. Retrieve a certain number of events.
3. Export a certain number of events to a file.

� Task 1: Retrieve a list of event logs


• Retrieve a list of the Windows event logs.

� Task 2: Retrieve a certain number of events


• Retrieve a list of the five newest/most recent events in the Windows Application event log.

� Task 3: Export a certain number of events to a file


• Retrieve a list of the five newest/most recent events in the Windows
Application event log and export the events to a CSV formatted file.

Results: After this exercise, you will have exported the five most recent events from the
Windows Application event log to a CSV file.
Lab A: Exercise 3: Comparing Objects Using XML

Scenario
You suspect that the status of a service is changing, and want to monitor that status of the service
so you can determine if its status has changed.
The main tasks for this exercise are carried out on WINDOWS7 and are as follows:
1. Retrieve a list of services.
2. Save a list of services to a XML formatted file.
3. Stop a service.
4. Compare services with different statuses.
5. Restart a service.

� Task 1: Retrieve a list of services


• Retrieve a list of services.

� Task 2: Save a list of services to an XML formatted file


• Retrieve a list of services and save the listing to an XML formatted file.

� Task 3: Stop a service


• Stop and thus change the status of the Windows Time service (“w32time”).

� Task 4: Compare services with different statuses


• Retrieve a new list of services and save the listing to an XML formatted file. (Use a different
file name than what was used in Task 2.)
• Using the data from the XML formatted files, compare the old and new list of services by
comparing the Status property.

Hint: When you specify a comparison property for the Compare-Object cmdlet, you can include more than one
property. To do so, provide list of properties for the cmdlet’s -property parameter, inserting a comma between each
property. For example, if you tell it only to compare the Status property, you will not be able to see the name of the
service. If you include both the State and Name properties, then you will see the name of the service.
� Task 5: Restart a service
• Change the status of the Windows Time service back to its original state.

Results: After this exercise, you will have determined that the Status property of two service
objects has changed after the Windows time service was modified.
Lab A: Exercise 4: Saving Objects to a CSV File

Scenario
You want to get a list of processes in a format that could be readable by Microsoft Excel to
produce management reports and metrics.
The main tasks for this exercise are carried out on WINDOWS7 and are as follows
1. Retrieve a list of processes.
2. Export a list of processes to a file.
3. Use a non-default separator.

� Task 1: Retrieve a list of processes


• Retrieve a list of running processes.

� Task 2: Export a list of processes to a file


• Retrieve a list of running processes and export them to a CSV formatted file.

� Task 3: Use a non-default separator


• Retrieve a list of running processes and export them to a CSV formatted file, but use a semi-
colon “;” as the delimiter.

Results: After this exercise, you will have exported a list of processes to a CSV file using the
default separator “,”, and the non-default separator “;”.
Lab A: Exercise 5: Measuring a Collection of Objects

Scenario
You are getting reports that there seem to be problems with one of the servers you are
monitoring, and want to get a quick report of the CPU time used by processes on the server.

The main tasks for this exercise are carried out on WINDOWS7 and are as follows
1. Retrieve a list of processes.
2. Measure the average, maximum, minimum, and average of a collection.

� Task 1: Retrieve a list of processes


• Retrieve a list of the running processes.

� Task 2: Measure the average, maximum and minimum of a collection


• Retrieve a list of the running processes and measure the average, maximum, and minimum of
the CPU property of the entire collection.

Results: After this exercise, you will have measured the average, minimum and maximum
values of the CPU property of all the running processes.
Lab B: Filtering and Enumerating Objects in the
Pipeline
Estimated time: 30 minutes
You are a system administrator. One of your tasks in the morning as your shift is starting is to
check the status of the processes and services for the servers you are responsible for. Lately, you
have a particular service installed on several computers that have been having issues. Your
corporate monitoring solution has not always been alerting that the service has stopped running.

Lab Setup
For this lab, you will use the available virtual machine environment. 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
4. Open a Windows PowerShell session as Administrator.
Lab B: Exercise 1: Comparing Numbers (Integer Objects)

Scenario
You need to check the status of processes and services on your server; however, before you
begin, verify that PowerShell’s comparison capabilities can indeed compare simple and complex
expressions.

Note: An integer object is any whole number, such as 4 or 5. Numbers that have a fraction, such
as 2.3, are not integers. Windows PowerShell can sometimes interpret a string as a number, when
the number is enclosed in quotation marks, such as “7.” However, integers are not normally
enclosed in quotation marks.

The main tasks for this exercise are carried out on WINDOWS7 and are as follows:
1. Compare using a simple expression.
2. Compare more complex expressions.

� Task 1: Compare using a simple expression


• Open Windows PowerShell and create an expression that determines whether 3 is greater than
5.

� Task 2: Compare using a more complex expression


• Create a complex expression that determines whether 3 is smaller than 4 and 5 is equal to 5.

Results: After this exercise, you will have determined that 3 is smaller than 5 by having True
returned, and also that the complex expression that compares whether 3 is smaller than 4 and 5 is
equal to 5 resolves to True because both sides of the complex expression alone resolve to True.
Lab B: Exercise 2: Comparing String Objects

Scenario
Continuing with the previous exercise, you want to expand the comparison to see how string
objects compare in PowerShell. In this exercise, look at both simple as well as complex
expressions.

Note: A string object is any sequence of characters that is enclosed within single or double
quotation marks, such as “powershell” or ‘windows.’

The main tasks for this exercise are carried out on WINDOWS7 and are as follows:
1. Compare using a simple expression.
2. Compare using a more complex expression.

� Task 1: Compare using a simple expression


• Create an expression that determines whether the string PowerShell is equal to powershell.

� Task 2: Compare using a more complex expression


• Create a complex expression that determines whether the string logfile is equal to logfiles and
host is equal to HOST. In the latter string, use a case-sensitive expression.

Results: After this exercise, you will have determined that PowerShell is considered equal to
powershell using the default comparison operators, and that the complex expression comparing
logfile to logfiles and host to HOST resolves to False because one side of the complex expression
alone resolves to False.
Lab B: Exercise 3: Retrieving Processes from a Computer

Scenario
With the previous exercises complete, you’re ready to try out PowerShell with a few
administrative activities. You manage a large number of servers and would like to use
PowerShell to easily query other servers to retrieve a list of the running processes.

The main tasks for this exercise are carried out on WINDOWS7 and are as follows:
1. Retrieve a list of processes.
2. Retrieve objects from a remote computer.

� Task 1: Retrieve a list of processes


• Retrieve a list of running processes.

� Task 2: Retrieve objects from a remote computer


• From WINDOWS7 , retrieve a list of running processes on AD.

Results: After this exercise, you will have retrieved the list of processes running remotely on AD
from WINDOWS7 .
Lab B: Exercise 4: Retrieving Services from a Computer

Scenario
You would like to use PowerShell to easily query other servers to retrieve a list of the services
installed.

The main tasks for this exercise are carried out on WINDOWS7 and are as follows:
1. Retrieve a list of services.
2. Retrieve objects from a remote computer.
3. Filter a collection of objects.

� Task 1: Retrieve a list of services


• Retrieve a list of services.

� Task 2: Retrieve objects from a remote computer


• From WINDOWS7 , retrieve a list of services from AD.

� Task 3: Filter a collection of objects


• From WINDOWS7 , retrieve a list of services from AD that have a name that starts with the
letter “w.”

Results: After this exercise, you will have retrieved a list of all the installed services that start
with the letter w on AD from WINDOWS7 .
Lab B: Exercise 5: Iterating Through a List of Objects

Scenario
You have a long list of systems that you administer that includes desktops, application servers,
and Active Directory servers. Often, you have to perform actions only on the application servers
so you need a method to be able to filter those out from the system list.

The main tasks for this exercise are carried out on WINDOWS7 and are as follows:
1. Create a file.
2. Import the contents of a file.
3. Iterate through a list of objects.
4. Filter a list of objects.

� Task 1: Create a file


• Create a txt file C:\Systems.txt with the below entries. You can do this from the powershell
command line if you are able or you can open Notepad and just enter the below data, each on a
single line if you need.
• WINDOWS7 .NewHorizons.com
• AD.NewHorizons.com

� Task 2: Import the contents of a file


• Retrieve the contents of the file created.

� Task 3: Iterate through a list of objects


• Retrieve the contents of the created file and display all the entries in lowercase.
• Start by running the command Get-Content –Path “C:\Systems.txt” | Get-
Member. Notice that the String objects each have several methods. To execute one of those
methods, you will reference the String object (in a
ForEach-Object script block—do so by using the $_ placeholder), type a period, then type the
method name, followed by parentheses. For example,
$_.ToUpper().
� Task 4: Filter a list of objects
• Retrieve the contents of the file created and display only the entries where the
name includes win.

Results: After this exercise, you will have retrieved a list of entries from a file, have changed all
the characters to lowercase, and have also filtered the list of entries to return only the ones with
the string win in the entry name.
Lab C: Using Pipeline Parameter Binding
Estimated time: 30 minutes

You are a system administrator for a company with about 100 users and desktop computers. You
want to perform a set of tasks against those users and computers using Windows PowerShell.
You want to accomplish those tasks using data from external files. You need to add a set of users
to Active Directory, using properlyformatted and improperly-formatted CSV files. You also need
to regularly reboot a set of computers based on the contents of a CSV file. Finally, you also need
to stop a list of processes on computers, based on the contents of a CSV file.

Lab Setup
For this lab, you will use the available virtual machine environment. Before you begin the lab,
you must:
1. Start the AD virtual machine, and then logon by using the following credentials:
• Username: NEWHORIZONS\administrator
• Password: Passw0rd
2. Start the WINDOWS7 virtual machine. You do not need to log on.
4. On AD, open a Windows PowerShell session as Administrator.

Lab C: Exercise 1: Using Advanced Pipeline Features

Scenario
You have created a properly-formatted CSV formatted file of new users that need to be added to
your Active Directory installation. You want to use PowerShell to automate the process.

The main tasks for this exercise are as follows:


1. Import the Active Directory module.
2. Import a CSV file.
3. Create users in Active Directory using advanced pipeline features.

� Task 1: Import the Active Directory module


• On AD, import the Active Directory module.

� Task 2: Import a CSV file


• Import the CSV file Module3_LabC_Exercise1.csv.

� Task 3: Create users in Active Directory


• Using advanced pipeline features, import the CSV file
Module3_LabC_Exercise1.csv, and create new Active Directory users.

Results: After this exercise, you will have automated the creation of users in the
NewHorizons.com domain.

Lab C: Exercise 2: Working with Multiple Computers


This is an optional exercise to complete if you have extra time, or if you want to explore on your
own.
Scenario
You manage several types of systems from clients, to servers, and domain controllers. You are
allowed to update and reboot servers before 8AM. You have a list in a CSV file of all the
systems in your company and only want to reboot the ones that are servers.

The main tasks for this exercise are carried out on AD and are as follows:
1. Create a CSV file.
2. Import a CSV file and filter the results.
3. Restart a group of computers.

� Task 1: Create a CSV file


• On AD, create a CSV file C:\Inventory.csv with the below contents. Again, you can do this
from the powershell command line if you are able or you can open Notepad and just enter the
below data, each on a single line if you need.
• Type,Name
• AD,AD
• Server,WINDOWS7

� Task 2: Import a CSV file and filter the results


• Import the CSV file created, and list only the systems where the Type is Server.

� Task 3: Restart a group of computers


• Import the CSV file created, and restart the systems where the Type is Server.

Note: If someone is logged in to WINDOWS7 you may receive an


error message. To overcome the error message and achieve a successful re-start the
virtual machines, log off from them and then re-run the script.

Results: After this exercise, you will have restarted a filtered group of servers.
Lab C: Exercise 3: Stopping a List of Processes

Scenario
There are a set of inappropriate processes that are currently running on systems within your
network. You have been given a CSV file that contains the list of computers and associated
processes that must be stopped on each computer.

The main tasks for this exercise are as follows:


1. Start 2 applications.
2. Create a CSV file.
3. Import a CSV file and iterate through a collection of objects.
4. Stop a list of processes.

� Task 1: Start two applications


• On AD, open one session of Notepad and Wordpad.

� Task 2: Create a CSV file


• Open Windows PowerShell and create a CSV file named C:\Process.csv with the following
entries.
• Computer,ProcName
• AD,Notepad
• AD,Wordpad

� Task 3: Import a CSV file and iterate through a collection of objects


• Import the CSV file created in the previous task, C:\Process.csv, and select the ProcName
property to display.

� Task 4: Stop a list of processes


• Import the CSV file created in Task 2, C:\Process.csv, and stop each of the processes listed.
Results: After this exercise, you will have stopped a list of processes based on values
imported from a CSV file.
Lab C: Exercise 4: Binding Properties to Parameters

Note: Complete this exercise only if you have finished the previous exercises and still have time
remaining. If you do not have time, you can complete this exercise on your own.

Scenario
You were provided a CSV formatted file with improper formatting. That file includes a second
set of new users that need to be added to your Active Directory installation. You want to use
PowerShell to automate the process.

The main tasks for this exercise are as follows:


1. Import a CSV file.
2. Create users in Active Directory.

� Task 1: Import a CSV file


• On AD, import the CSV file
Module3_LabC_Exercise4.csv.

� Task 2: Create users in Active Directory


• Import the CSV file Module3_LabC_Exercise4.csv and create new Active Directory users by
specifically binding properties to parameters. From the CSV file, map the properties according to
the following table:
CSV file property New-ADUser parameter
EmployeeName Name and SamAccountName
Town City
Unit Department
Id EmployeeNumber
• Also, hard code the value for the Company parameter as NewHorizons.
Hint: You have already seen the syntax used to rename a property. You will have to repeat this syntax once for each
property than you want to rename. To save typing, you may wish to complete this task in the Windows PowerShell
ISE. That will allow you to type the syntax once, and then copy and paste it (and modify the values of each pasted
copy) to help reduce the amount of typing.

Results: After this exercise, you will have automated the creation of 20 users in the
NewHorizons.com domain.

You might also like