Beruflich Dokumente
Kultur Dokumente
6434A
Lab Instructions and Answer Key:
Automating Windows Server 2008 ®
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual
property rights covering subject matter in this document. Except as expressly provided in any
written license agreement from Microsoft, the furnishing of this document does not give you any
license to these patents, trademarks, copyrights, or other intellectual property.
The names of manufacturers, products, or URLs are provided for informational purposes only and
Microsoft makes no representations and warranties, either expressed, implied, or statutory,
regarding these manufacturers or the use of the products with any Microsoft technologies. The
inclusion of a manufacturer or product does not imply endorsement of Microsoft of the
manufacturer or product. Links may be provided to third party sites. Such sites are not under the
control of Microsoft and Microsoft is not responsible for the contents of any linked site or any link
contained in a linked site, or any changes or updates to such sites. Microsoft is not responsible for
webcasting or any other form of transmission received from any linked site. Microsoft is providing
these links to you only as a convenience, and the inclusion of any link does not imply endorsement
of Microsoft of the site or the products contained therein.
© 2008 Microsoft Corporation. All rights reserved.
Microsoft, and Windows are either registered trademarks or trademarks of Microsoft Corporation in
the United States and/or other countries.
All other trademarks are property of their respective owners.
Module 1
Lab Instructions: Introduction to Windows
PowerShell™
Contents:
Exercise 1: Installing Windows PowerShell 2
Exercise 2: Customizing Windows PowerShell 3
2 Lab Instructions: Introduction to Windows PowerShell™
Exercise Overview
In this exercise you will select and install the correct build of
Windows PowerShell v1.0.
The main tasks for this exercise are as follows:
1. Start the 6434A-NYC-DC1 virtual machine and log on as Administrator.
2. Verify that the Windows PowerShell system requirements are met.
3. Install Windows PowerShell.
Lab Instructions: Introduction to Windows PowerShell™ 3
Results: After this exercise, you should have installed Windows PowerShell on
6434A-NYC-DC1.
Exercise Overview
In this exercise you will set the script execution policy in Windows PowerShell and
customize the appearance of the Windows PowerShell console window.
The main tasks for this exercise are as follows:
1. Set the script execution policy.
4 Lab Instructions: Introduction to Windows PowerShell™
Results: After this exercise, you should have set the script execution policy to allow for
script execution, and customized the Windows PowerShell console window.
Lab Instructions: Overview of Windows PowerShell™ 1
Module 2
Lab Instructions: Overview of Windows
PowerShell™
Contents:
Exercise 1: Learning Cmdlets and Defining Aliases 2
Exercise 2: Holding the Output of a Cmdlet 3
2 Lab Instructions: Overview of Windows PowerShell™
Exercise Overview
In this exercise, you will identify the cmdlets necessary to perform specific tasks,
and you will create a new alias to one of those cmdlets.
The main tasks for this exercise are as follows:
Lab Instructions: Overview of Windows PowerShell™ 3
Results: After this exercise, you should have identified two cmdlets and created an
alias for one of those cmdlets.
Exercise Overview
In this exercise you will run a cmdlet and retain its output in a variable.
The main tasks for this exercise are as follows:
1. Obtain the currently running processes and store them in a variable.
2. Display the processes stored in a variable.
Results: After this exercise, you should have run a cmdlet and retained its output in a
variable. You should also have displayed the contents of that variable.
Lab Instructions: Building Pipelines for Assembly-Line Style Processing 1
Module 3
Lab Instructions: Building Pipelines for
Assembly-Line Style Processing
Contents:
Exercise 1: Evaluating Process Properties Using the Get-Member Cmdlet 2
Exercise 2: Calculating Process Memory Usage 3
Exercise 3: Using Associative Array Variables 4
Exercise 4 Sorting and Selecting Elements from a Resultant Set of Data 5
2 Lab Instructions: Building Pipelines for Assembly-Line Style Processing
Exercise Overview
In this exercise you will use the Get-Member cmdlet to identify various properties
of a Process object.
The main tasks for this exercise are as follows:
Lab Instructions: Building Pipelines for Assembly-Line Style Processing 3
Results: After this exercise, you should have discovered the Process object properties
that represent the virtual memory utilization, paged memory utilization, and non-
paged memory utilization of a process.
Exercise Overview
In this exercise, you will use Windows PowerShell to calculate the memory usage
for the processes running on a computer.
The main tasks for this exercise are as follows:
1. Display memory utilization statistics for running processes.
Results: After this exercise, you should have displayed various memory utilization
statistics for the processes running on a computer.
Exercise Overview
In this exercise you will create and utilize an associative array.
The main tasks for this exercise are as follows:
1. Create an associative array and populate it with values.
2. Display specified members of an associative array.
Lab Instructions: Building Pipelines for Assembly-Line Style Processing 5
Results: After this exercise, you should have created an associative array and displayed
specific values from within the array.
Exercise Overview
In this exercise you will retrieve the currently running processes and display them
in a sorted table that includes a subset of the processes and their properties.
The main tasks for this exercise are as follows:
1. Sort processes into the desired order.
2. Select the desired properties of a process.
6 Lab Instructions: Building Pipelines for Assembly-Line Style Processing
Results: After this exercise, you should have created a table that displays a sorted
subset of running processes.
Lab Instructions: Managing Processes and Formatting Cmdlet Output 1
Module 4
Lab Instructions: Managing Processes and
Formatting Cmdlet Output
Contents:
Exercise 1: Implementing Basic Formatting Control 2
Exercise 2: Formatting with the -f Operator 4
Exercise 3: Implementing Advanced Formatting 5
2 Lab Instructions: Managing Processes and Formatting Cmdlet Output
Exercise Overview
In this exercise you will use formatting cmdlets to create basic customized
formatting.
The main tasks for this exercise are as follows:
1. Start the 6434A-NYC-DC1 virtual machine, log on as Administrator, and start
Windows PowerShell.
2. Format services in a table.
Lab Instructions: Managing Processes and Formatting Cmdlet Output 3
Results: After this exercise, you should have five custom-formatted displays for various
operating system object types.
4 Lab Instructions: Managing Processes and Formatting Cmdlet Output
Exercise Overview
In this exercise, you will use the -f operator to provide custom formatting for
various operating system objects and data.
The main tasks for this exercise are as follows:
1. Insert data into a string.
2. Insert numerically formatted data into a string.
3. Insert date-formatted data into a string.
Results: After this exercise, you should have produced various strings that include
formatted data.
Exercise Overview
In this exercise you will use the Format-Table cmdlet to implement advanced
formatting, including calculated columns in a table.
The main tasks for this exercise are as follows:
1. Prototype a calculated column using the -f operator
2. Create a table that contains a calculated column
6 Lab Instructions: Managing Processes and Formatting Cmdlet Output
Results: After this exercise, you should have created a table that uses a calculated
column.
Lab Instructions: Introduction to Scripting with Windows PowerShell™ 1
Module 5
Lab Instructions: Introduction to Scripting with
Windows PowerShell™
Contents:
Exercise 1: Writing and Running a Script 2
Exercise 2: Customizing Profiles 3
2 Lab Instructions: Introduction to Scripting with Windows PowerShell™
Exercise Overview
In this exercise you will write a Windows PowerShell script that displays specified
information about running processes.
The main tasks for this exercise are as follows:
1. Start the 6434A-NYC-DC1 virtual machine and log on as Administrator.
2. Create an empty script file.
3. Add Windows PowerShell commands to the script.
4. Run the script and verify its operation.
Lab Instructions: Introduction to Scripting with Windows PowerShell™ 3
Results: After this exercise, you should have created a script which, when executed,
displays information about processes running on the server.
Exercise Overview
In this exercise you will create a Windows PowerShell profile and configure it to
automatically create aliases each time that the shell is opened.
The main tasks for this exercise are as follows:
1. Create a blank profile script.
2. Add commands to the profile.
3. Test the profile and verify its operation.
Results: After this exercise, you should have created a Windows PowerShell profile
that automatically creates aliases each time the shell is opened.
Lab Instructions: Implementing Flow Control and Functions 1
Module 6
Lab Instructions: Implementing Flow Control
and Functions
Contents:
Exercise 1: Adding Flow Control in a Script 2
Exercise 2: Creating Functions 4
2 Lab Instructions: Implementing Flow Control and Functions
Exercise Overview
In this exercise, you will control the flow of processing of script code blocks.
The main tasks for this exercise are as follows:
1. Start the 6434A-NYC-DC1 virtual machine, log on as Administrator, and start
Windows PowerShell.
Lab Instructions: Implementing Flow Control and Functions 3
2. Retrieve the Windows build number and service pack version from a
computer.
3. Write a script that uses the build number to display the operating system
version.
f Task 2: Retrieve the Windows build number and service pack version
from a computer
• Use the Get-WmiObject cmdlet to retrieve the Win32_OperatingSystem class
from 6434A-NYC-DC1
• Store the retrieved class in a variable.
• Use the -computerName parameter of Get-WmiObject to specify NYC-DC1 as
the computer name.
• Use the variable containing the retrieved class to display the BuildNumber
and ServicePackMajorVersion properties.
f Task 3: Write a script that uses the build number to display the
operating system version
• Create a new, blank script named Mod6Task3.ps1.
• To the script, add commands that accomplish the following tasks:
• Store the computer name NYC-DC1 into a variable named $computer.
• Use Get-WmiObject to retrieve the Win32_OperatingSystem class from
the computer name stored in $computer. Store the retrieved class in a
variable named $os.
• Store "0" in a variable named $osver.
• Use a switch construct to examine the BuildNumber property of the $os
variable. Store a short version of the operating system version in the
variable $osver, according to the following rules:
4 Lab Instructions: Implementing Flow Control and Functions
Results: After this exercise, you should have created a script that retrieves and displays
the operating system version and latest installed service pack version from a specified
computer.
Exercise Overview
In this exercise, you will create a function and add it to their profile.
The main tasks for this exercise are as follows:
1. Rewrite Mod6Task3.ps1 as a function.
2. Add the function to your Windows PowerShell profile.
Results: After this exercise, you should have created the Get-OSVersion function and
added it to your profile.
Lab Instructions: Working with Files, the Registry, and Certificate Stores 1
Module 7
Lab Instructions: Working with Files, the
Registry, and Certificate Stores
Contents:
Exercise 1: Searching for Certain Files 2
Exercise 2: Modifying Registry Entries 4
Exercise 3: Generating Reports 5
Exercise 4: Generating Reports on the Security Log 6
Exercise 5: Comparing Files 7
2 Lab Instructions: Working with Files, the Registry, and Certificate Stores
Exercise Overview
In this exercise, you will search within a folder for all files of a certain type, for files
having a certain name, and for files that contain a particular text string that
represents the trademarked name of a product.
Lab Instructions: Working with Files, the Registry, and Certificate Stores 3
Results: After this exercise, you should have located files of a specified file type, or files
having a specified name. You should also have located all files containing a specified
trademarked term.
4 Lab Instructions: Working with Files, the Registry, and Certificate Stores
Exercise Overview
In this exercise, you will modify a set of registry entries, changing the TrustPolicy
settings for Windows Script Host.
The main tasks for this exercise are as follows:
1. Modify the WinSAFER registry setting for WSH
2. Create the TrustPolicy setting for the WSH
Results: After this exercise, you should have modified the WSH registry settings so that
only scripts that are digitally signed will be executed, regardless of the Software
Restriction Policies settings.
Lab Instructions: Working with Files, the Registry, and Certificate Stores 5
Exercise Overview
In this exercise, you will generate a report of disallowed files on a server, and of
large files on a server.
The main tasks for this exercise are as follows:
1. Produce a report showing disallowed files
2. Produce a report showing large files
Results: After this exercise, you should have produced two reports that can be used to
help clean up the file system of a server.
Exercise Overview
In this exercise, you will scan the system event log for all instances of a particular
event ID and generate a CSV file containing the results.
The main tasks for this exercise are as follows:
1. Retrieve audit events that match the specified criteria
2. Create a report using the retrieved audit events
Results: After this exercise, you should have created a CSV report containing the
specified audit events.
Lab Instructions: Working with Files, the Registry, and Certificate Stores 7
Exercise Overview
In this exercise, you will create a baseline of installed services on a computer. You
will then install new services, and demonstrate how the baseline can be used to
audit the current configuration of the server and display discrepancies.
The main tasks for this exercise are as follows:
1. Create a baseline of installed services
2. Install additional services on the computer
3. Compare the baseline to the current state
Results: After this exercise, you should have created a baseline configuration file and
used it to audit the services that are installed on a server.
8 Lab Instructions: Working with Files, the Registry, and Certificate Stores
Lab Instructions: Managing the Windows Operating System Using Windows PowerShell™ and WMI 1
Module 8
Lab Instructions: Managing the Windows
Operating System Using Windows PowerShell™
and WMI
Contents:
Exercise 1: Using WMI Classes in Windows PowerShell 2
Exercise 2: Using WMI Type Accelerators 4
Exercise 3: Managing Disk Volumes in Windows PowerShell 5
Exercise 4: Defragmenting Disk Volumes Using Windows PowerShell 6
Exercise 5: Managing IIS 7.0 Properties Using WMI 7
2 Lab Instructions: Managing the Windows Operating System Using Windows PowerShell™ and WMI
Exercise Overview
In this exercise, you will use WMI classes in Windows PowerShell.
The main tasks for this exercise are as follows:
1. Start the 6434A-NYC-DC1 virtual computer and log on as Administrator.
2. Retrieve the operating system and service pack version information from a
computer.
3. Retrieve information related to services that are installed on a computer.
4. Remove a shared folder from a computer.
Results: After this exercise, you should have retrieved inventory and operational
information from a computer using a technique that can be used for either the local
computer or for remote computers.
Exercise Overview
In this exercise, you will create a shared folder and launch a new process.
The main tasks for this exercise are as follows:
1. Create a folder to share.
2. Share the folder.
3. Launch a new process.
Results: After this exercise, you should have created a new shared folder and launched
Windows Notepad.
Exercise Overview
In this exercise, you will manage disk volumes in Windows PowerShell.
The main tasks for this exercise are as follows:
1. Report on free disk space for local disk volumes.
2. Report on all volumes attached to a computer.
Results: After this exercise, you should have produced drive volume reports that can
be used for inventory and capacity planning purposes.
Exercise Overview
The main tasks for this exercise are as follows:
1. Defragment the E drive.
Results: After this exercise, you should have defragmented the E drive on your virtual
machine.
Lab Instructions: Managing the Windows Operating System Using Windows PowerShell™ and WMI 7
Exercise Overview
In this exercise, students will manage IIS 7.0 properties by using WMI.
The main tasks for this exercise are as follows:
1. Start the 6434A-NYC-DC1 virtual machine and log on as Administrator.
2. Install IIS 7.0
3. Write the Get-WebSiteStatus function.
4. Write the Restart-WebSite function.
The function must accept the name of a Web site as an input argument, and
the function must output the state of the Web site: Running, Stopped,
Stopping, Starting, or Unknown.
The function should use WMI to retrieve the specified Web site, execute its
GetState() method, and display the result.
• Use the function to retrieve the status of the default Web site.
Results: After this exercise, you should have written two functions that help make
IIS 7.0 Web site maintenance easier.
Lab Instructions: Administering Microsoft® Active Directory® with Windows PowerShell™ 1
Module 9
Lab Instructions: Administering Microsoft®
Active Directory® with Windows PowerShell™
Contents:
Exercise 1: Managing Active Directory Domain and Forest Properties 2
Exercise 2: Maintaining Active Directory with ADSI 4
Exercise 3: Maintaining Relationships in Active Directory with ADSI 6
Exercise 4: Managing IIS 7.0 with the .NET Web.Administration.ServerManager
Class 7
2 Lab Instructions: Administering Microsoft® Active Directory® with Windows PowerShell™
Exercise Overview
In this exercise, students will manage Active Directory domain and forest
properties.
The main tasks for this exercise are as follows:
1. Obtain a reference to the domain.
2. Display domain password policy properties.
Results: After this exercise, you should have displayed the domain password policies
for your domain.
4 Lab Instructions: Administering Microsoft® Active Directory® with Windows PowerShell™
Exercise Overview
In this exercise, students will maintain Active Directory objects using ADSI in
Windows PowerShell.
The main tasks for this exercise are as follows:
1. Write a script that creates an organizational unit.
2. Create a sample CSV file.
3. Write a script that imports the CSV file and creates user accounts.
f Task 3: Write a script that imports the CSV file and creates
user accounts
• Write a Windows PowerShell script that performs the following steps:
• Read the contents of the CSV file.
• For each line in the file, excluding the first row, create a new user account.
• The "FullName" column is the canonical name (CN) of the user.
• The "LogonName" column is the SAM Account Name of the user.
• The "Branch" column is the Department of the user.
• The new user accounts should be disabled (this is the default).
• The user accounts must be created in the Tellers OU.
Results: After this exercise, you should have written a script that reads a CSV file and
uses the information in it to create new user accounts.
6 Lab Instructions: Administering Microsoft® Active Directory® with Windows PowerShell™
Exercise Overview
In this exercise, students will manage relationships between user accounts and
groups using ADSI in Windows PowerShell.
The main tasks for this exercise are as follows:
1. Retrieve the user account of the new manager.
2. Update the accounts of selected users.
Results: After this exercise, you should have updated two user accounts to have a new
manager attribute.
Scenario
You are a Web server administrator for Woodgrove Bank. For security reasons,
new promotions and new products need to be published to separate Web sites that
are distinct from the regular Web sites for the bank. Because these new promotions
come out regularly, new Web sites need to be created frequently. You want to write
a Windows PowerShell script that automates the creation of new IIS 7.0 Web sites.
Exercise Overview
In this exercise, students will manage IIS 7.0 by using the .NET
Web.Administration.ServerManager class.
The main tasks for this exercise are as follows:
1. Write a Windows PowerShell script that creates a new Web site.
f Task 1: Write a Windows PowerShell script that creates a new Web site
• Write a script that accepts several parameters:
• Web site root directory path
• Web site name
• Web site HTTP port
8 Lab Instructions: Administering Microsoft® Active Directory® with Windows PowerShell™
The script should create a new IIS 7.0 Web site on the local computer, using
the parameters that are provided.
• Test the script by using it to create a new Web site named MyWeb, with a root
path of C:\Inetpub\wwwroot2, and a port of 8080.
• Check your results in Microsoft® Internet Explorer® by browsing to
http://localhost:8080.
Results: After this exercise, you should have created a script that automates the
creation of new IIS 7.0 Web sites.
Lab Instructions: Administering Group Policy in Windows PowerShell™ Using COM 1
Module 10
Lab Instructions: Administering Group Policy in
Windows PowerShell™ Using COM
Contents:
Exercise 1: Retrieving a GPO by Using a COM Object 2
Exercise 2: Copying Group Policy Settings 3
Exercise 3: Backing Up and Restoring a GPO 4
Exercise 4: Generating Group Policy Reports 5
2 Lab Instructions: Administering Group Policy in Windows PowerShell™ Using COM
Exercise Overview
In this exercise, you will use COM objects in Windows PowerShell.
The main tasks for this exercise are as follows:
1. Start the 6434A-NYC-DC1 virtual machine and log on as Administrator.
2. Retrieve the GPO that has the display name GPO1, and store it in a variable.
Lab Instructions: Administering Group Policy in Windows PowerShell™ Using COM 3
f Task 2: Retrieve the GPO that has the display name GPO1, and store it
in a variable
• Instantiate the GPMC COM object.
• Retrieve a reference to the woodgrovebank.com domain.
• Create GPO search criteria and retrieve all GPOs in the domain.
• Use the Where-Object cmdlet to filter out all GPOs except the one that has the
display name "GPO1".
• Store the GPO in a variable named $gpo.
Results: After this exercise, you should have retrieved the GPO named GPO1 and
stored it in the variable $gpo.
Exercise Overview
In this exercise, students will copy Group Policy settings from one GPO to another.
The main tasks for this exercise are as follows:
1. Copy the Group Policy object GPO1 to GPO3.
4 Lab Instructions: Administering Group Policy in Windows PowerShell™ Using COM
Results: After this exercise, you should have copied GPO1 to GPO3.
Exercise Overview
In this exercise, students will back up and restore GPOs.
The main tasks for this exercise are as follows:
1. Back up the GPO1 GPO.
2. Delete the GPO1 GPO.
3. Restore the GPO1 GPO.
Results: After this exercise, you should have backed up, deleted, and restored a GPO.
Exercise Overview
In this exercise, you will generate Group Policy change reports.
The main tasks for this exercise are as follows:
1. Create an HTML report of the backed-up GPO named GPO1.
Results: After this exercise, you should have viewed an HTML report of a backed-up
GPO.
Lab Answer Key: Introduction to Windows PowerShell™ 1
Module 1
Lab Answer Key: Introduction to Windows
PowerShell™
Contents:
Exercise 1: Installing Windows PowerShell 2
Exercise 2: Customizing Windows PowerShell 4
2 Lab Answer Key: Introduction to Windows PowerShell™
Exercise Overview
In this exercise you will select and install the correct build of Windows PowerShell
v1.0.
Note: This document refers to the domain controller by its virtual machine name
6434A-NYC-DC1, whereas the internal computer name in the Windows server within
that virtual machine is NYC-DC1. The VM name and Windows computer name are
not identical.
Lab Answer Key: Introduction to Windows PowerShell™ 3
Results: After this exercise, you should have installed Windows PowerShell on
6434A-NYC-DC1.
4 Lab Answer Key: Introduction to Windows PowerShell™
Exercise Overview
In this exercise you will set the script execution policy in Windows PowerShell,
and customize the appearance of the Windows PowerShell console window.
Results: After this exercise, you should have set the script execution policy to allow for
script execution, and customized the Windows PowerShell console window.
Lab Answer Key: Overview of Windows PowerShell™ 1
Module 2
Lab Answer Key: Overview of Windows
PowerShell™
Contents:
Exercise 1: Learning Cmdlets and Defining Aliases 3
Exercise 2: Holding the Output of a Cmdlet 4
2 Lab Answer Key: Overview of Windows PowerShell™
Exercise Overview
In this exercise, you will identify the cmdlets necessary to perform specific tasks,
and you will create a new alias to one of those cmdlets.
Results: After this exercise, you should have identified two cmdlets and created an
alias for one of those cmdlets.
Exercise Overview
In this exercise you will run a cmdlet and retain its output in a variable.
Lab Answer Key: Overview of Windows PowerShell™ 5
Results: After this exercise, you should have run a cmdlet and retained its output in a
variable. You should also have displayed the contents of that variable.
Lab Answer Key: Building Pipelines for Assembly-Line Style Processing 1
Module 3
Lab Answer Key: Building Pipelines for
Assembly-Line Style Processing
Contents:
Exercise 1: Evaluating Process Properties Using the Get-Member Cmdlet 3
Exercise 2: Calculating Process Memory Usage 4
Exercise 3: Using Associative Array Variables 5
Exercise 4: Sorting and Selecting Elements from a Resultant Set of Data 6
2 Lab Answer Key: Building Pipelines for Assembly-Line Style Processing
Exercise Overview
In this exercise you will use the Get-Member cmdlet to identify various properties
of a Process object.
Results: After this exercise, you should have identified the Process object properties
that represent the virtual memory utilization, paged memory utilization, and non-
paged memory utilization of a process.
Exercise Overview
In this exercise, you will use Windows PowerShell to calculate the memory usage
for the processes running on a computer.
Results: After this exercise, you should have displayed various memory utilization
statistics for the processes running on a computer.
Lab Answer Key: Building Pipelines for Assembly-Line Style Processing 5
Exercise Overview
In this exercise you will create and utilize an associative array.
Note: The prompt ">>" indicates that line continuation rules are in effect. If you see
the ">>" prompt, it means that the lines that you type will be considered as part of
the prior line. Therefore, either continue to type more if you are continuing the
command that you started (or continued) in the previous line, or type a blank line at
the ">>" prompt to end the current statement or command if you are finished
entering that command.
6 Lab Answer Key: Building Pipelines for Assembly-Line Style Processing
Results: After this exercise, you should have created an associative array and displayed
specific values from within the array.
Exercise Overview
In this exercise you will retrieve the currently running processes and display them
in a sorted table that includes a subset of the processes and their properties.
Results: After this exercise, you should have created a table that displays a sorted
subset of running processes.
Lab Answer Key: Managing Processes and Formatting Cmdlet Output 1
Module 4
Lab Answer Key: Managing Processes and
Formatting Cmdlet Output
Contents:
Exercise 1: Implementing Basic Formatting Control 2
Exercise 2: Formatting with the -f Operator 4
Exercise 3: Implementing Advanced Formatting 5
2 Lab Answer Key: Managing Processes and Formatting Cmdlet Output
Exercise Overview
In this exercise you will use Windows PowerShell formatting cmdlets to create
basic customized formatting.
Note: Ensure that you are typing each command at a regular Windows PowerShell
prompt (for example, PS C:\Users\Administrator>). If the prior command has not
been completed, and you have a line continuation prompt (for example, >>) then
type CTRL+C prior to entering a new command.
Lab Answer Key: Managing Processes and Formatting Cmdlet Output 3
Results: After this exercise, you should have five custom formatted displays for various
operating system object types.
4 Lab Answer Key: Managing Processes and Formatting Cmdlet Output
Exercise Overview
In this exercise, you will use the -f operator to provide custom formatting for
various operating system objects and data.
Note: Take special care when you are typing format strings. When you use format
strings such as "{0:d}" or "{1:N0}" be sure to use braces on either side of the
parameter specifier, and a colon (not a comma) between the parameter number (for
example, 0, 1, etc.) and the format type (for example, "d", "N0"). Additionally, be
careful not to introduce a space between a numeric value and the multiplier suffix
such as 1MB; this must be written as 1MB and not 1 MB.
Results: After this exercise you should have produced various strings that include
formatted data.
Exercise Overview
In this exercise you will use the Format-Table cmdlet to implement advanced
formatting, including calculated columns in a table.
Results: After this exercise you should have created a table that uses a calculated
column.
Lab Answer Key: Introduction to Scripting with Windows PowerShell™ 1
Module 5
Lab Answer Key: Introduction to Scripting with
Windows PowerShell™
Contents:
Exercise 1: Writing and Running a Script 2
Exercise 2: Customizing Profiles 4
2 Lab Answer Key: Introduction to Scripting with Windows PowerShell™
Exercise Overview
In this exercise you will write a Windows PowerShell script that displays specified
information about running processes.
Results: After this exercise, you should have created a script which, when executed,
displays information about processes running on the server.
4 Lab Answer Key: Introduction to Scripting with Windows PowerShell™
Exercise Overview
In this exercise you will create a Windows PowerShell profile and configure it to
automatically create aliases each time that the shell is opened.
Results: After this exercise, you should have created a Windows PowerShell profile
that automatically creates aliases each time the shell is opened.
Lab Answer Key: Implementing Flow Control and Functions 1
Module 6
Lab Answer Key: Implementing Flow Control
and Functions
Contents:
Exercise 1: Adding Flow Control in a Script 3
Exercise 2: Creating Functions 5
2 Lab Answer Key: Implementing Flow Control and Functions
f Task 2: Retrieve the Windows build number and service pack version
from a computer
1. Type $wmi = Get-WmiObject Win32_OperatingSystem –computerName
NYC-DC1, and press ENTER.
2. Type $wmi | select BuildNumber,ServicePackMajorVersion, and press
ENTER.
4 Lab Answer Key: Implementing Flow Control and Functions
f Task 3: Write a script that uses the build number to display the
operating system version
1. Ensure that the folder C:\Scripts exists. If it does not, create it using Windows
Explorer.
2. In Windows Explorer, open the C:\Scripts folder, right-click in the right pane,
point to New, and select Text Document.
3. Name the text document Mod6Task3.ps1.
4. Accept the change in filename extension.
5. Right-click Mod6Task3.ps1 and select Open to open the file in Windows
Notepad.
6. In Notepad, type the following commands, pressing ENTER after each line:
$computer = "NYC-DC1"
$os = Get-WmiObject Win32_OperatingSystem –computerName
$computer
$osver = "0"
switch ($os.BuildNumber) {
2195 { $osver="Win2000" }
2600 { $osver="WinXP" }
3790 { $osver="Win2003" }
6000 { $osver="Vista" }
default { $osver="Win2008" }
}
$output = "{0}: build {1} : {2}" -f $computer,$os.buildnumber,$osver
Write-Host $output
Lab Answer Key: Implementing Flow Control and Functions 5
Note: If the current location in the shell is the folder in which you saved the script,
then you can use a relative path such as .\Mod6Task3.ps1. Alternatively, you can
use an absolute full path. When you use an absolute full path, be sure to either
include grave accents before spaces or use quotation marks around the whole
path.
Question: How can you learn about the properties that are available for the
Win32_OperatingSystem class?
Answer: Run Gwmi win32_operatingsystem | gm and examine the output of
Get-Member.
Results: After this exercise, you should have created a script that retrieves and displays
the operating system version and latest installed service pack version from a specified
computer.
Note: Consider making the changes using a technique similar to the following:
First, add the function declaration line Function Get-OSVersion( $computer ){ at
the top of the file. Next, mark the end of the function by putting a line with a
closing brace } at the end of the file. Then add the line Get-OSVersion NYC-DC1 to
the end of the file. Modify the body of the function as follows. Delete the line
$computer = "NYC-DC1" because the computer name is now passed as an
argument parameter to the function. Change Write-Host to return (toward the
bottom of the function). Consider indenting all lines in the body of the function by
pressing TAB at the beginning of each line in the function.
Lab Answer Key: Implementing Flow Control and Functions 7
Results: After this exercise, you should have created the Get-OSVersion function and
added it to your profile.
Lab Answer Key: Working with Files, the Registry, and Certificate Stores 1
Module 7
Lab Answer Key: Working with Files, the
Registry, and Certificate Stores
Contents:
Exercise 1: Searching for Certain Files 3
Exercise 2: Modifying Registry Entries 5
Exercise 3: Generating Reports 6
Exercise 4: Generating Reports on the Security Log 7
Exercise 5: Comparing Files 8
2 Lab Answer Key: Working with Files, the Registry, and Certificate Stores
Exercise Overview
In this exercise, you will search within a folder for all files of a certain type, for files
having a certain name, and for files that contain a particular text string that
represents the trademarked name of a product.
Note: The grave accent character after the word Program escapes the normal
interpretation of the following space character, such that "C:\Program Files" is
considered as the value of the -Path parameter to the Set-Location cmdlet, which
is aliased as cd. Without the grave accent, the space between the words Program
and Files separates "C:\Program" as a value of the -Path parameter, and "Files" as
another parameter. This would generate an error such as "A parameter cannot be
found that matches the parameter name 'files'.
This example uses the grave accent. However, you can also use either apostrophes
or quotation marks (also known as single or double quotes) around the space or
around the whole path value, such as "C:\Program Files"
Results: After this exercise, you should have located files of a specified file type, or files
having a specified name. You should also have located all files containing a specified
trademarked term.
Lab Answer Key: Working with Files, the Registry, and Certificate Stores 5
Exercise Overview
In this exercise, you will modify a set of registry entries, changing the TrustPolicy
settings for Windows Script Host.
f Task 1: Modify the WinSAFER registry setting for Windows Script Host
1. Open Windows PowerShell.
2. Type Cd "HKLM:\Software\Microsoft\Windows Script Host\Settings" and
press ENTER.
3. Type Set-ItemProperty . usewinsafer 0 and press ENTER.
Question: What happens if you run this command from the
HKLM:\Software\Microsoft\Windows Script Host\ folder?
Answer: Because the UseWinSAFER value is a property of the Settings items,
you have to be in the Settings item in order to use this command as shown.
Alternatively, you could stay in the WSH key and run Set-ItemProperty
Settings usewinsafer 0. This alternate command specifies the path of the Item
so that Windows PowerShell can retrieve the property.
f Task 2: Create the TrustPolicy setting for the Windows Script Host
1. Type Cd "HKLM:\Software\Microsoft\Windows Script Host\Settings" and
press ENTER.
2. Type New-ItemProperty -path . -name TrustPolicy -type dword -value 2 and
press ENTER.
Results: After this exercise, you should have modified the WSH registry settings so that
only scripts that are digitally signed will be executed, regardless of the Software
Restriction Policies settings.
6 Lab Answer Key: Working with Files, the Registry, and Certificate Stores
Exercise Overview
In this exercise, you will generate a report of disallowed files on a server, and of
large files on a server.
Note: Ensure that you use Set-Location (alias cd) to a file system path prior to
working with files at relative paths, in case the current location is in another store,
such as the registry.
Results: After this exercise, you should have produced two reports that can be used to
help clean up the file system of a server.
Lab Answer Key: Working with Files, the Registry, and Certificate Stores 7
Exercise Overview
In this exercise, you will scan the system event log for all instances of a particular
event ID and generate a CSV file containing the results.
Results: After this exercise, you should have created a CSV report containing the
specified audit events.
8 Lab Answer Key: Working with Files, the Registry, and Certificate Stores
Exercise Overview
In this exercise, you will create a baseline of installed services on a computer. You
will then install new services and demonstrate how the baseline can be used to
audit the current configuration of the server and display discrepancies.
Results: After this exercise, you should have created a baseline configuration file and
used it to audit the services that are installed on a server.
Lab Answer Key: Managing the Windows Operating System Using Windows PowerShell™ and WMI 1
Module 8
Lab Answer Key: Managing the Windows
Operating System Using Windows PowerShell™
and WMI
Contents:
Exercise 1: Using WMI Classes in Windows PowerShell 2
Exercise 2: Using WMI Type Accelerators 4
Exercise 3: Managing Disk Volumes in Windows PowerShell 5
Exercise 4: Defragmenting Disk Volumes Using Windows PowerShell 6
Exercise 5: Managing IIS 7.0 Properties Using WMI 7
2 Lab Answer Key: Managing the Windows Operating System Using Windows PowerShell™ and WMI
Exercise Overview
In this exercise, you will use WMI classes in Windows PowerShell.
Results: After this exercise, you should have retrieved inventory and operational
information from a computer, using a technique that could be used for either the local
computer or for remote computers.
4 Lab Answer Key: Managing the Windows Operating System Using Windows PowerShell™ and WMI
Exercise Overview
In this exercise, you will create a shared folder and launch a new process.
Note: For the syntax of the Create() method, see Create Method of the
Win32_Share Class.
Note: For the syntax of the Create() method, see Create Method of the
Win32_Process Class.
Results: After this exercise, you should have created a new shared folder and launched
Windows Notepad.
Exercise Overview
In this exercise, you will manage disk volumes in Windows PowerShell.
Results: After this exercise, you should have produced drive volume reports that can
be used for inventory and capacity planning purposes.
Results: After this exercise, you should have defragmented the E drive on your virtual
machine.
Lab Answer Key: Managing the Windows Operating System Using Windows PowerShell™ and WMI 7
Exercise Overview
In this exercise, students will manage IIS 7.0 properties by using WMI.
8. On the Select Role Services page, scroll down to the bottom of the services list.
Under Management Tools, do the following:
• IIS Management Console: This check box is already selected. Leave it
selected.
• IIS Management Scripts and Tools: Select this check box.
• Management Service: Select this check box. The Add Features Required
for Management Service dialog box pops up. Click Add Required
Features.
• IIS 6 Management Compatibility: Select this check box.
9. On the Select Role Services page, click Next.
10. On the Confirm Installation Selections page, click Install.
11. On the Installation Results page, click Close.
12. Close Server Manager.
Results: After this exercise, you should have written two functions that help make
IIS 7.0 Web site maintenance easier.
Lab Answer Key: Administering Microsoft® Active Directory® with Windows PowerShell™ 1
Module 9
Lab Answer Key: Administering Microsoft®
Active Directory® with Windows PowerShell™
Contents:
Exercise 1: Managing Active Directory Domain and Forest Properties 2
Exercise 2: Maintaining Active Directory with ADSI 4
Exercise 3: Maintaining Relationships in Active Directory with ADSI 7
Exercise 4: Managing IIS 7.0 with the .NET Web.Administration.ServerManager
Class 8
2 Lab Answer Key: Administering Microsoft® Active Directory® with Windows PowerShell™
Exercise Overview
In this exercise, students will manage Active Directory domain and forest
properties.
Results: After this exercise, you should have displayed the domain password policies
for your domain.
Exercise Overview
In this exercise, students will maintain Active Directory objects using ADSI in
Windows PowerShell.
Lab Answer Key: Administering Microsoft® Active Directory® with Windows PowerShell™ 5
f Task 3: Write a script that imports the CSV file and creates user
accounts
1. Click Start, click Run, type Notepad, and click OK.
2. In the file, type the following information:
$users = Import-Csv c:\scripts\users.csv
$ou = [ADSI]"LDAP://ou=Tellers,dc=woodgrovebank,dc=com"
foreach ($user in $users) {
$cn = "cn=" + $user.fullname
$account = $ou.create("user",$cn)
$account.put("SAMAccountName",$user.logonname)
$account.put("Department",$user.branch)
$account.setinfo()
}
3. From the File menu, select Save As.
4. Type C:\Scripts\Users.ps1 and click Save.
5. Close Notepad.
6. In Windows PowerShell, type C:\Scripts\Users.ps1 and press ENTER.
Question: Why are the user accounts disabled by default?
Answer: This is a default behavior of Windows Server 2008. It is designed so
that user accounts cannot actually be used until they are explicitly enabled.
This approach creates a more secure-by-default environment.
Results: After this exercise, you should have written a script that reads a CSV file and
uses the information in it to create new user accounts.
Lab Answer Key: Administering Microsoft® Active Directory® with Windows PowerShell™ 7
Exercise Overview
In this exercise, students will manage relationships between user accounts and
groups using ADSI in Windows PowerShell.
Note: It is important to use dot sourcing when running the getuser.ps1 script
because the Get-User function in that script is not defined with global scope. Be
careful to place a space between the first and second dots. Additionally, note that
the name of the script is intentionally different than the function that it defines.
The script is named getuser.ps1 whereas the function is named Get-User. The
same guidelines also apply to setuser.ps1.
Results: After this exercise, you should have updated two user accounts to have a new
manager attribute.
Exercise Overview
In this exercise, students will manage IIS 7.0 by using the .NET
Web.Administration.ServerManager class.
Lab Answer Key: Administering Microsoft® Active Directory® with Windows PowerShell™ 9
f Task: Write a Windows PowerShell script that creates a new Web site
1. In Windows Explorer, on the C drive, create a new folder called inetpub. In
the inetpub folder, create a subfolder called wwwroot2.
2. Open Notepad. Write a script that accepts the following parameters,
remembering to press ENTER after each command:
Param($dir,$name,$port)
$iisDir = "$env:SystemRoot\System32\inetsrv"
[System.Reflection.Assembly]::LoadFrom(
"$iiSDir\Microsoft.Web.Administration.dll" )
$iisManager = New-Object Microsoft.Web.Administration.ServerManager
$site = $iisManager.Sites.Add( $name, $dir, $port )
$site.Sites($name).ServerAutoStart = $True
$iisManager.CommitChanges()
3. Save the script as C:\Scripts\NewSite.ps1. Exit Notepad.
4. In Windows PowerShell, type C:\Scripts\NewSite c:\inetpub\wwwroot2
MyWeb 8080 and press ENTER.
5. Click Start, click Run, type http://localhost:8080, and click OK.
Question: How could this script be made part of a larger Web site
provisioning script?
Answer: Encapsulate the script in a function named New-WebSite, and
include the function in any other script that requires this functionality.
Results: After this exercise, you should have created a script that automates the
creation of new IIS 7.0 Web sites.
Lab Answer Key: Administering Group Policy in Windows PowerShell™ Using COM 1
Module 10
Lab Answer Key: Administering Group Policy in
Windows PowerShell™ Using COM
Contents:
Exercise 1: Retrieving a GPO by Using a COM Object 2
Exercise 2: Copying Group Policy Settings 4
Exercise 3: Backing Up and Restoring a GPO 5
Exercise 4: Generating Group Policy Reports 7
2 Lab Answer Key: Administering Group Policy in Windows PowerShell™ Using COM
Exercise Overview
In this exercise, you will use COM objects in Windows PowerShell.
f Task 2: Retrieve the GPO that has the display name GPO1 and store it
in a variable
• Type the following commands, making sure to press ENTER after each:
$gpmc = New-Object –comObject GPMgmt.Gpm
$domain = $gpmc.GetDomain("woodgrovebank.com","","")
$gpo1 = $domain.CreateGPO()
$gpo1.DisplayName = "GPO1"
$sc = $gpmc.CreateSearchCriteria()
$all = $domain.SearchGPOs($sc)
Lab Answer Key: Administering Group Policy in Windows PowerShell™ Using COM 3
Note: The value of $gpo must be defined for the following exercises to be
completed successfully.
Results: After this exercise, you should have retrieved the GPO named GPO1 and
stored it in the variable $gpo.
4 Lab Answer Key: Administering Group Policy in Windows PowerShell™ Using COM
Exercise Overview
In this exercise, students will copy Group Policy settings from one GPO to another.
Results: After this exercise, you should have copied GPO1 to GPO3.
Lab Answer Key: Administering Group Policy in Windows PowerShell™ Using COM 5
Exercise Overview
In this exercise, students will back up and restore GPOs.
Results: After this exercise, you should have backed up, deleted, and restored a GPO.
Lab Answer Key: Administering Group Policy in Windows PowerShell™ Using COM 7
Exercise Overview
In this exercise, you will generate Group Policy change reports.
Results: After this exercise, you should have viewed an HTML report of a backed-up
GPO.