Lab_Module_3
Lab_Module_3
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Results: After this exercise, you will have automated the creation of users in the
NewHorizons.com domain.
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.
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.
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.
Results: After this exercise, you will have automated the creation of 20 users in the
NewHorizons.com domain.