You are on page 1of 12

55316A – Administering a SQL Database

Infrastructure
PowerShell Setup Guide

(Microsoft Azure or Hyper-V)

2022/06/07

Author: Neil R. Tucker


Table of Contents

Introduction ....................................................................................................................................................................1
Licensing ........................................................................................................................................................................ 1
55316 Server Setup ....................................................................................................................................................... 1
Microsoft Azure PowerShell ........................................................................................................................................... 2
Create Azure Virtual Machines ...................................................................................................................................3
Hyper-V PowerShell ....................................................................................................................................................... 4
Customizing the Setup ................................................................................................................................................... 5
Clean Up ........................................................................................................................................................................ 8
55316A PowerShell Setup Guide

Introduction
PowerShell is used to automate the setup of the 55316 class. This can be done on any modern Windows
client or server system with at least 16GB RAM and 200GB of free drive space. Microsoft Azure may also
be leveraged for the classroom computer deployment. A PowerShell deployment has a number of
advantages including the following:

1. The setup can be completed in less than one hour.


2. The scripts can be easily modified to setup other Microsoft classes.
3. An “emergency setup” for a student or for testing purposes is much faster & easier.
4. The class setup can be easily customized for blended & bootcamp deliveries.
5. Online and Internet Deliveries can be more easily facilitated.

You must be using a minimum of PowerShell 3.0 on Windows Server 2012 or Windows 8 to use this guide.
Experience using and editing PowerShell scripts will be helpful. There are free resources online and a free
PowerShell tutorial (PowerShell For Technology Professionals) is also included with the course for trainer
use, but may also be used to help students who want to build their own class labs.

Licensing
The training center or any organization hosting the lab computers for this class are fully responsible for the
licensing of all software used in the course and labs. This can be mitigated by using an Azure deployment
for the class.

55316 Server Setup


There are two setup methods available for creating the virtual machine used for the 55316A class labs:
1. Microsoft Azure PowerShell
2. Hyper-V PowerShell

We will discuss the requirements for an Azure setup first, and then Hyper-V. Both methods will use
Windows PowerShell (version 5.1 or higher) so some experience using it will be useful. The setups are
mostly automated so a lot of scripting experience will not be necessary. Before using PowerShell for any
setup, ensure the modules on the host machine are up-to-date and always use an Administrator console
when running either setup.

1
55316A PowerShell Setup Guide

Microsoft Azure PowerShell


This is the faster and easier setup option if you have a Microsoft Azure subscription. The
55316AzureSetup.ps1 script is used to configure a Windows Server domain controller running multiple
instances of SQL Server 2019.

If you elect to use Azure VMs for the class labs, the Azure Az PowerShell module must be installed on the
host machine. The previous version of Azure PowerShell (AzureRM) is not used for this setup and the
scripts will run best with that older version being uninstalled first. They can co-exist on the same system
however, by following the instructions in the Microsoft online documentation for running Azure Az
PowerShell cmdlets. If the Azure Az module needs to be installed, run the following command:
• Find-Module Az -IncludeDependencies | Install-Module -Force

The class setup files are available from the Courseware Marketplace (http://shop.courseware-
marketplace.com) or SkillPipe (http://skillpipe.courseware-marketplace.com. Create a folder named
Labfiles.55316 on the C: drive of the host machine. Extract all the files and folders from 55316A-
ENU_PowerShellSetup.zip to the C:\Labfiles.55316 folder.

The following variables in the C:\Labfiles\55316AzureSetup.ps1 file should be configured before running
the script:
• $SubscriptionID: The “Subscription Name” of your Azure account
• $Labfiles: Change this option if C:\Labfiles.55316 cannot be used for the setup files.
• $namePrefix: Change “init” to use the initials of your name
• $TimeZone: Change “Eastern Standard Time” to the local time zone

The script is mostly automatic and will only ask for your Azure subscription credentials at the beginning of
the process. The VM should be created in 60 – 75 minutes. When the script is finished, a text file named
55316AzureSetup[DateTime].txt will be created in the $Labfiles location (preferably C:\Labfiles). The
Internet IP addresses for the VMs can be located in this file. Use the Remote Desktop application to connect
to the virtual machines using their Internet IPs.

Here are a few recommendations to keep in mind when working with Microsoft Azure virtual machines:
1. Regularly check your balance on the Azure Portal to ensure there are enough funds for the class.
2. Store unrelated objects in separate Resource Groups.
3. Make sure that Storage Account names are in lower case.
4. Delete resources as soon as you are finished working with them.
5. To include additional files on the VM hard-drive, add them to the C:\Labfiles\Tools folder.

2
55316A PowerShell Setup Guide

Create Azure Virtual Machines


Verify that files in the C:\Labfiles.55316\55316A-ENU_PowerShellSetup.zip archive have been
extracted to the C:\Labfiles.55316 folder. Perform all the following steps with administrator credentials:

1. From an “Administrator: Command Prompt”, start a PowerShell session and execute the script
C:\Labfiles.55316\55316AzureSetup.ps1. The script should not be interrupted. Do not proceed
until the script is finished. This may take about 15 - 30 minutes.

2. When the previous step is complete, connect to the domain controller (55316-MIA-SQL) using the
Remote Desktop Connection application. Instead of using the computer name, use the Internet IP
address specified in the C:\Labfiles.55316\55316AzureSetup[DateTimeStamp].txt file. Connect
using the Contoso\Student account with a password of Pa$$w0rd. If there was an error during the
setup, you should be able to connect using the Adminz account with a password of
Pa$$w0rdPa$$w0rd.

3. If there were problems during the setup, delete the existing virtual machines and create new ones
using the 55316AzureSetup.ps1 script. Before attempting a new setup, verify the parameters in the
script and the information in this section of the setup. Azure VMs can be restarted using the
Restart-AzureRMVM cmdlet. Get-AzureRMVM will provide the status of existing VMs.

3
55316A PowerShell Setup Guide

Hyper-V PowerShell
This setup method requires a computer already Hyper-V on Windows 10 or later with an up-to-date
distribution of Hyper-V PowerShell tools. In addition to the setup files for the class, three ISO images
must be downloaded to the C:\Labfiles.55316 folder and renamed as shown below:
1. Windows Server 2022 (Rename to ws2022.iso)
2. SQL Server 2019 Enterprise or Developer (Rename to sql2019.iso)
3. SQL Server Management Studio (Rename to SSMS-Setup-ENU.exe)

Windows Server 2022 will be configured as a domain controller for the domain CONTOSO.com. A default
instance of SQL Server will be configured with the Database Engine and Integration Services installed. A
second instance (SQL2) will also be installed with the Database Engine and Full Text Indexing. SSMS will
be installed using the default options.

Verify that files in the C:\Labfiles.55316\55316A-ENU_PowerShellSetup.zip file have been extracted.


Perform all the following steps with administrator credentials:

1. From an “Administrator: Command Prompt”, start a PowerShell session and execute the script
C:\Labfiles.55316\55316_Setup.ps1. The script should not be interrupted. Do not proceed until
the script is finished. This can take up to 10 minutes.

2. When the previous step is complete, verify that the VM (55316-MIA-SQL) setup is complete by
connecting to it in Hyper-V Manager. You may login as Administrator or Student with a
password of Pa$$w0rd. This part of the process may take between 30 and 45 minutes to complete.

3. Verify that SQL Server is running properly and check for operating system and application error
messages.

4. If you need Internet connectivity for the VM, you may need to disable the “Private” network adapter
to allow the “External” or “Internet” adapter to connect successfully. Disabling and re-enabling
the Internet adapter on the host machine may also be necessary. Review Hyper-V documentation
on the Microsoft documentation website. A number of troubleshooting tasks may be necessary,
including manually assigning a valid Internet DNS Server IP to the VMs Internet adapter (e.g.
1.1.1.1).

Note: You must provide a valid Product Key for Windows Server 2022 for the setup to work. Replace the invalid key
in autounattend.xml (e.g. 11111-22222-33333-44444-55555) which is stored in C:\Labfiles.55316\dc1install.vfd.

4
55316A PowerShell Setup Guide

Customizing the Setup


The setup specified in the previous section can be customized for modular/blended deliveries of 55316 or
other Microsoft classes. To change the image settings, modify the C:\Labfiles.55316\55316_setup_ps3.ps1
file. The variables at the beginning of the file allow you to change the memory, drive & network settings.
The memory settings used should leave at least 1GB of RAM (2GB recommended) for the host machine.
The C:\Labfiles\HostMemory.reg.txt file has a sample registry update entry that might be used to make this
change (Read your Hyper-V documentation for more details before making any such changes). The drive
settings should leave at least 20% free space on the partition selected. Here is a description of the more
important variables. Some of them may not be used for this setup:

$DC1 The name of the image used to install the domain controller (DC).
$SRV1 The name of the image used to install the Windows Server.
$DCRAM The amount of memory assigned to the DC
$SRAM The amount of memory assigned to the Windows Server.
$Labfiles The location of the setup files.
$SRV1VHD The size of the virtual hard drive used by Windows Server.
$DCISO The name and location of the ISO used to install the DC.
$WSISO The name and location of the ISO used to install Windows Server.
$VMLOC The location where you want the image VHD or VHDX files to be created.
$Network1 The virtual network connection shared by the client and server computers.
$Network2 The second virtual network connection used by the server or DC.

If the script is used to configure multiple groups of images on the same machine, the $NetworkX variables
should be modified. The script looks for and removes these virtual networks before recreating them. For
faster setups, the ISO variables (e.g. $DCISO & $WSISO) can point to files on separate drives.

5
55316A PowerShell Setup Guide

55316_Setup_ps3.ps1

For additional details about the Hyper-V PowerShell cmdlets used in the 55316_setup_ps3.ps1 script, use
the following commands:
• Get-Command –Module Hyper-V
• Get-Help <Hyper-V Cmdlet> -Examples

When using the setup files to configure classes other than 55316, you have the option of changing computer
name, Active Directory (AD), DHCP, DNS, Printer and IP settings. The VFD (Virtual Floppy Disks) must
be modified to do this. Windows 7 is configured with the w7install.vfd file and Windows Server with the
wsinstall.vfd file. The files on these virtual floppy drives can be modified by using an existing Hyper-V
image or with tools like WinImage.

To change the computer name, modify the Autounattend.xml file on the VFD using Notepad. On the
Windows 7 VFD, search and replace all occurrences of Student1 with the new name you choose. On the
Windows Server VFD, search and replace occurrences of NYC-DC1.

6
55316A PowerShell Setup Guide

Autounattend.xml

To change the Active Directory configuration, modify the dcunattend.old file. This file replaces
dcunattend.txt file during the setup process. To import and add domain objects after AD is setup, modify
the ad.cmd file. Familiarity with the ldifde.exe, dsadd.exe, dsmod.exe, dsacls.exe and net.exe commands
is necessary to understand this file.

The DHCP Server settings can be modified by changing the dhcp.cmd file. It configures the service and
imports scope settings from the dhcpdb file. An easy way to modify this service is to export your existing
DHCP Server database using the netsh.exe command and replace the existing database file on the floppy
(e.g. netsh dhcp server export dhcpdb all).

The DNS Server is installed during the configuration of Active Directory and configured using the dns.cmd
file. Familiarity with the dnscmd.exe command is needed before changing this file that creates and
configures DNS zones (e.g. dnscmd /zoneadd xyz.com /dsprimary).

The shared printers are configured on the server using the rundll32 command in the run2.cmd file. These
commands should be edited with care since some of the parameters are case-sensitive.

The static IP settings for the server are configured using PowerShell cmdlets in ip.ps1. The netsh.exe
command can also be used to perform this task.

7
55316A PowerShell Setup Guide

Clean Up
After you are finished with an image it can be deleted from the Hyper-V Manager. Make sure that you also
remove the VHD file(s) associated with that image by going to the $VMLOC folder and deleting it.

Hyper-V Manager (Deleting an image)

8
55316A PowerShell Setup Guide

Windows Explorer (Deleting VHD files)

9
55316A PowerShell Setup Guide

10

You might also like