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

Module 5 - Implementing Desired State Configuration

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

Module 5 - Implementing Desired State Configuration

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

Infrastructure

Modernization
Hands-On Lab | Step-by-Step Guide

Module 5 Implementing Desired State


Configuration
Lab version: 1.0.0
Last updated: October 24, 2014

Cloud OS - Hands-On Lab | Modernizing your infrastructure

Contents
Contents
CONTENTS ............................................................................................................................... 2
OVERVIEW................................................................................................................................ 3
OBJECTIVES ............................................................................................................................ 3
LAB 1: EXPLORING WINDOWS POWERSHELL DESIRE STATE CONFIGURATION ........... 4
EXERCISE 1.1: REVIEWING WINDOWS POWERSHELL DESIRED STATE
CONFIGURATION COMPONENTS........................................................................................... 4
EXERCISE 1.2: IMPLEMENTING BASIC DSC ......................................................................... 6
EXERCISE 1.2: IMPLEMENTING MORE DETAILED DSC ....................................................... 9
EXERCISE 1.3: IMPLEMENT REPEATABLE CONFIGURATION AND CHANGE CONTROL 11
EXERCISE 1.4: USING ONEGET TO INSTALL PACKAGES ................................................. 12
LAB 2: USING WINDOWS POWERSHELL DESIRED STATE CONFIGURATION FOR
SHAREPOINT ......................................................................................................................... 14
EXERCISE 2.1: IMPLEMENT REPEATABLE CONFIGURATION AND CHANGE CONTROL 14

Copyright 2014 by Microsoft Corporation. All rights reserved.

Cloud OS - Hands-On Lab | Modernizing your infrastructure

Overview
In Lab 1, you will explore some of the new enhancements in management for Windows Server 2012 R2.
You will then explore a key new feature called Windows PowerShell Desired State Configuration (DSC).
This feature allows you provide standardization of services across server farms and server deployments
for specific roles within your organization. DSC makes use of different types of resources to extend the
type of server functionality validation.
In Lab 2, you will implement a pre-created configuration script to prepare a server to receive a
SharePoint 2013 installation. This exercise is an example of how DSC scripts can be created and
distributed to simplify the process of server installation.
Estimated time to complete this module

60 minutes

Objectives
After completing this module, you will be able to:

Implement Windows PowerShell Desired State Configuration.


Implement a pre-created configuration script to prepare a server to receive a SharePoint 2013
installation.

To perform the exercises for this module you must first launch the lab environment called IM203A
Desired State Configuration Environment. The computers included in the environment are listed in the
following table.
Virtual Machine

Role

DC

Windows Server 2012 R2 Datacenter domain controller

Admin

Windows 8.1 Professional

Server1

Windows Server 2012 R2 Datacenter member server

All user accounts in this lab use the password Passw0rd!

Cloud OS - Hands-On Lab | Modernizing your infrastructure

Lab 1: Exploring Windows PowerShell


Desire State Configuration
In this lab, you will explore some of the new enhancements in management for Windows Server 2012
R2. You will then explore a key new feature called Windows PowerShell Desired State Configuration
(DSC). This feature allows you provide standardization of services across server farms and server
deployments for specific roles within your organization. DSC makes use of different types of resources
to extend the type of server functionality validation.

Exercise 1.1: Reviewing Windows PowerShell Desired State


Configuration components
In this task, you will review the different types of resources used by Windows PowerShell Desired State
Configuration. The resources to use are presented as providers.
1. Begin this task logged on to Server1 as Contoso\Administrator using the password Passw0rd!
2. Using File Explorer, navigate to
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PS
Providers.

The resources available are:


4

Cloud OS - Hands-On Lab | Modernizing your infrastructure


Resource

Purpose

Archive

Unpack archive files (.zip) at a path

Registry

Manage registry keys and values

Script

Ability to run Windows PowerShell script blocks

Package

Install and manage MSI packages

Environment

Manage system environment variables

Group

Manage local groups

User

Manage local user accounts

Service

Manage services

File

Manage files and folders

Log

Write messages to the Microsoft-Windows-Desired State


Configuration event log

Process

Configure processes

Role

Add or remove Windows Roles and Features

Cloud OS - Hands-On Lab | Modernizing your infrastructure

Exercise 1.2: Implementing basic DSC


In this task, you will use create a DSC script to deploy fully functional websites to an un-configured
Windows Server 2012 R2 server. You will also learn how DSC can be used to mitigate configuration drift.
Begin this task logged on to Admin as Contoso\Administrator using the password Passw0rd!
1. On the taskbar, right-click the Windows PowerShell icon, and then click Windows PowerShell
ISE.

2. On the File menu, click New Remote PowerShell Tab.

3. In the New Remote PowerShell Tab window, in computer, type Server1, and then in the User
name, type Administrator, and then click Connect.

Cloud OS - Hands-On Lab | Modernizing your infrastructure


4. Enter the password Passw0rd! when prompted, and then click OK.
5. On the View menu, click Show Script Pane.
6. In the Windows PowerShell ISE Script Pane, type the following commands, pressing ENTER after
each one.
The code for this script file can also be found in c:\LabFiles\DSC-Scripts.ps1. Instead of typing you can
optionally copy the relevant code sections from that file.
You will be creating a script to add IIS and ASP.NET 4.5 to Server1.
Configuration IISWebsite
{
Node Server1
{
WindowsFeature IIS
{
Ensure = Present
Name = Web-Server
}
WindowsFeature ASP
{
Ensure = Present
Name = Web-Asp-Net45
}
}
}
IISWebSite
7. Save the script in c:\Labfiles\ as DSC-Server1-IIS.ps1.
8. Press F5 to run the file. This basic state configuration file describes the desire to have a basic
web server with ASP.NET 4.5 installed.
The output of this configuration statement is a MOF file for the server Server1, in a folder named
IISWebSite. The folder represents the configuration set, and the MOF file a specific NODE (Server) in
that configuration set.
9. In Windows PowerShell ISE, type the following commands, pressing ENTER after each one.
This will verify that the web server and ASP.NET are not installed, apply the desired state which will
install the web server and ASP.NET, and then verify the results.
Get-WindowsFeature ComputerName Server1 Name Web-ASP*
Start-DSCConfiguration ComputerName Server1 Path IISWebSite Wait Verbose
Get-WindowsFeature ComputerName Server1 Name Web-ASP*
WEB-ASP-NET45 is now installed.
7

Cloud OS - Hands-On Lab | Modernizing your infrastructure

10. In Windows PowerShell ISE, type the following command, and then press ENTER.
Get-Service Name W3SVC ComputerName Server1
This will verify that the web server and website are now running,

Cloud OS - Hands-On Lab | Modernizing your infrastructure

Exercise 1.2: Implementing more detailed DSC


In this task, you will expand the Windows PowerShell Desired State Configuration setup to include the
configuration of a website, in addition to the basic installation requirement deployed in the previous
tasks.
Begin this task logged on to Admin as Contoso\Administrator using the password Passw0rd!
1. In the Windows PowerShell ISE Script Pane, review the script we used in the previous exercise
and add the following commands on line 15 after the closing brace in the ASP WindowsFeature
section.
This script is a file block. It will copy the BakeryWebsite content from a source directory to the
standard IIS folder path.
The code for this script file can also be found in c:\LabFiles\DSC-Scripts.ps1. Instead of typing, you
can copy the relevant code sections from that file.
File WebContent
{
Ensure = Present
Type = Directory
SourcePath = C:\labfiles\Source\BakeryWebsite
DestinationPath = C:\inetpub\WWWRoot\
Recurse = $true
}
2. Press F5 to run the file.
This configuration set, in addition to ensuring the role for web server is present, will configure the
initial website by copying the files from a distribution source. It will produce an updated MOF file.

3. Using Internet Explorer, navigate to http://server1.


The default home page will be displayed.

Cloud OS - Hands-On Lab | Modernizing your infrastructure

4. In Windows PowerShell ISE, type the following command, and then press ENTER.
Start-DSCConfiguration ComputerName Server1 Path IISWebSite Wait Verbose
5. In Internet Explorer, refresh the website Server1.

10

Cloud OS - Hands-On Lab | Modernizing your infrastructure

Exercise 1.3: Implement repeatable configuration and change control


In this task, you will use DSC to recover from a change to a website which results in the website being
down.
Begin this task logged on to Admin as Contoso\Administrator using the password Passw0rd!
1. In Windows PowerShell ISE, type the following command, and then press ENTER.
REMOVE-ITEM \\Server1\c$\inetpub\wwwroot\images -Force
2. Click Yes to All.
3. Navigate to http://server1.
Note that all images are missing. You may need to clear the IE cache.

4. In Windows PowerShell ISE, type the following command, and then press ENTER.
Start-DSCConfiguration ComputerName Server1 Path IISWebSite Wait Verbose
5. In Internet Explorer, refresh the website Server1.

11

Cloud OS - Hands-On Lab | Modernizing your infrastructure

Exercise 1.4: Using OneGet to Install Packages


Windows Management Framework 5.0 includes the OneGet module. OneGet is used to discover and
install packages from web-based repositories such as Chocolatey. It allows you to quickly add software
packages via script without having to worry about the complexities of automated installations. For this
exercise, the preview edition of WMF 5.0 has been installed.
To perform this exercise you must first launch the lab environment called Azure Active Directory Sync.

Virtual Machine

Role

AzureITC-DC

Windows Server 2012 R2 domain controller

AzureITC-Admin

Windows 8.1 Professional

AzureITC-Edge

Windows Server 2012 R2 member server

Begin this task logged on to AzureITC-Admin.


1. Open Windows PowerShell ISE as Administrator.
2. Type the following command, and then press ENTER. This command will load the OneGet
module.
Import-Module OneGet
3. Type the following command, and then press ENTER. This command will list the commands in
the OneGet Module.
Get-Command Module OneGet
4. Type the following command, and then press ENTER. This command will list all packages on the
Chocolatey repository.
This command will take a few minutes to complete.
Find-Package
When prompted to install the NuGet package manager, click Yes.
5. Type the following command, and then press ENTER. This command will find the SysInternals
tools package on the Chocolatey repository.

This command will take a few minutes to complete.

Find-Package sysinternals
12

Cloud OS - Hands-On Lab | Modernizing your infrastructure


6. Type the following command, and then press ENTER. This command will install the SysInternals
tools from the Chocolatey repository.
This command will take a few minutes to complete.
Find-Package sysinternals | install-package -verbose
When prompted to install the package, click Yes.
7. Using File Explorer, navigate to c:\Tools\Sysinternals to see the installed tools.
8. Optionally, use the above commands to install the Safari and Google Chrome packages to add
additional web browsers.

Close and discard the lab environment. You will return to the IM203A Desired State Configuration
Environment for the next exercise.

13

Cloud OS - Hands-On Lab | Modernizing your infrastructure

Lab 2: Using Windows PowerShell


Desired State Configuration for
SharePoint
In this lab, you will implement a pre-created configuration script to prepare a server to receive a
SharePoint 2013 installation. This exercise is an example of how DSC scripts can be created and
distributed to simplify the process of server installation.
The prerequisites for SharePoint Foundation are extensive and take quite a bit of time to apply. Only
complete this exercise if you are prepared to wait up to 15 minutes. This is due to extensive
installation and the need to download some components from the Internet.

Exercise 2.1: Implement repeatable configuration and change control


In this task, you will use DSC to recover from the removal of a key item in the registry needed for local
access to the SharePoint site that will be deployed.
Begin this task logged on to Admin as Contoso\Administrator using the password Passw0rd!
1. In the Windows PowerShell ISE console you left open from the previous exercise, open the file
C:\LabFIles\DSC-SharePoint.ps1.
This file includes all role prerequisites needed for a SharePoint Foundation 2013 deployment.

You may observe that the Media Foundation has been marked as commented, causing it to be
skipped. Media Foundation requires a system restart so it was omitted from this configuration run
simply to expedite the configuration processing.
If you open a new Windows PowerShell ISE console, ensure that you connect to Server1 using the
New Remote PowerShell tab from the File menu.
14

Cloud OS - Hands-On Lab | Modernizing your infrastructure


2. Press F5 to run the file.
This configuration set, in addition to ensuring web server role is present, will configure the initial
website by copying the files from a distribution source. It will produce an updated MOF file.

3. In Windows PowerShell ISE, type the following command, and then press ENTER.
Start-DSCConfiguration ComputerName Server1 Path SharePointPrereq Wait Verbose
This command may take up to 15 minutes to complete.

4. In Windows PowerShell ISE, type the following command, and then press ENTER.
Get-ItemProperty Path HKLM:\SYSTEM\CurrentControlSet\Control\LSA
-Name DisableLoopbackCheck
The value and entry for DisableLoopbackCheck is presented.
5. In Windows PowerShell ISE, type the following command, and then press ENTER.
Remove-ItemProperty Path HKLM:\SYSTEM\CurrentControlSet\Control\LSA
-Name DisableLoopbackCheck
The registry key is removed.
6. In Windows PowerShell ISE, type the following command, and then press ENTER:
Get-ItemProperty Path HKLM:\SYSTEM\CurrentControlSet\Control\LSA
-Name DisableLoopbackCheck
15

Cloud OS - Hands-On Lab | Modernizing your infrastructure


The value and entry for DisableLoopbackCheck is no longer listed and the command returns an error.
7. In Windows PowerShell ISE, type the following command, and then press ENTER:
Start-DSCConfiguration ComputerName Server1 Path SharePointPrereq Wait Verbose
8. In Windows PowerShell ISE, type the following command, and then press ENTER.
Get-ItemProperty Path HKLM:\SYSTEM\CurrentControlSet\Control\LSA
-Name DisableLoopbackCheck
The value and entry for DisableLoopbackCheck is presented and restored based on the
standardization of the configuration for Server1.

Close and discard the lab environment.

16

You might also like