Quantcast
Channel: Deployment Research - Johan Arwidmark
Viewing all articles
Browse latest Browse all 168

Script to build and activate 25 virtual machines against a KMS Server

$
0
0

If you ever need a script that deploys and activates 25 virtual machines against a KMS Server, here it is. The solution is based on a MDT 2013 deployment share, and a script that deploys the VMs. The script is for Hyper-V only, but can easily be adjusted for VMware.

Download

Download the Hydration Kit and the script that build the 25 virtual machines (11 kb).

Shorthand, there are three steps you need to do:

  • Download the necessary software
  • Prepare the Hydration Environment
  • Deploy the virtual machines using the script

Detailed instructions are further down this page... see the Step-by-Step Guide Guide section

image
The task sequence that builds and activates the virtual machine.

Step-by-Step Guide

Download the necessary software

  • On the machine (client or server) that you use to manage Hyper-V or VMware, create the C:\Downloads folder.
  • Download the following software:

    • The Hydration Kit sample files (download)
    • MDT 2013
    • Windows ADK 8.1 (make sure you download the re-release that was available after October 17).
    • Windows 8.1 Enterprise x64

Note #1: To download ADK 8.1 run adksetup.exe /layout "C:\Downloads\ADK 8.1"

 

 

Step 2 - Prepare the Hydration Environment

Create the hydration deployment share

  1. On the Windows machine that you use to manage Hyper-V or VMware, install Windows ADK 8.1 (adksetup.exe) selecting only the following components:

    Deployment Tools
    Windows Preinstallation Environment (Windows PE)

    ADKSetup
    The Windows ADK 8.1 Setup.

  2. Install MDT 2013 (MicrosoftDeploymentToolkit2013_x64.msi) with the default settings.
  3. Extract the HydrationKMS.zip sample file to C:\.
  4. You should now have the following folder containing a few subfolders and PowerShell scripts.
    C:\HydrationKMS\Source

  5. In an elevated (run as Administrator) PowerShell command prompt, configure Execution Policy in PowerShell by typing the following command:
    Set-ExecutionPolicy Unrestricted –Force

    Note:
    If you are running Windows Server 2012 R2 on your machine you don’t need to set the policy, it’s set by default.

  6. In the PowerShell command prompt, create the hydration deployment share by running the following command:

    C:\HydrationKMS\Source\CreateHydrationDeploymentShare.ps1

    image
    The result after running the CreateHydrationDeploymentShare.ps1 script.

Populate the hydration deployment share with the downloaded files

  1. Copy the Windows 8.1 Enterprise x64 installation files (the content of the ISO, not the actual ISO) to the following folder:
    C:\HydrationKMS\DS\Operating Systems\W81X64

Create the hydration ISO (MDT 2013 offline media item)

  1. Using Deployment Workbench (available on the Start screen), expand Deployment Shares, and expand Hydration KMS.
  2. Review the various nodes. The Operating Systems and Task Sequences nodes should all have some content in them.

image
The Hydration deployment share, listing the windows 8.1 task sequence.

  1. Expand the Advanced Configuration node, and then select the Media node.
  2. In the right pane, right-click the MEDIA001 item, and select Update Media Content.

After the media update you will have a somewhat big ISO (HydrationKMS.iso ) in the C:\HydrationKMS\ISO folder. The HydrationKMS.iso should be about 4 GB in size.

image
The HydrationKMS.iso

 

 

Step 3 - Deploy the virtual machines

Note: Since the build is completely automated, and the VM is deleted once deployed you probably never need to logon, but if you do, the Administrator account have a password of P@ssw0rd. Also, if you need to change the KMS server name, simply change the KMSServer value in the C:\HydrationKMS\ISO\Content\Deploy\Control\CustomSettings.ini file.

Deploying the 25 virtual machines

In the PowerShell command prompt, create the 25 virtual machines (deployed one at the time) by running the following command:

C:\HydrationKMS\Source\Build25VMs.ps1

Here is the Build25VMs.ps1 script:

$VMLocation = "D:\VMs"
$VMISO = "C:\HydrationKMS\ISO\HydrationKMS.iso"
$VMNetwork = "Internal"
$NumberOfVMs = '25'

$i = 1
do {

    Write-Host "Creating VM $i of $NumberOfVMs"

    # Create the virtual machines, one at a time
    $VMName = "KMS$i"
    $VMMemory = 1024MB
    $VMDiskSize = 40GB
    New-VM -Name $VMName -BootDevice CD -MemoryStartupBytes $VMMemory -SwitchName $VMNetwork -Path $VMLocation -NoVHD -Verbose
    New-VHD -Path "$VMLocation\$VMName\Virtual Hard Disks\$VMName-Disk1.vhdx" -SizeBytes $VMDiskSize -Verbose
    Add-VMHardDiskDrive -VMName $VMName -Path "$VMLocation\$VMName\Virtual Hard Disks\$VMName-Disk1.vhdx" -Verbose
    Set-VMDvdDrive -VMName $VMName -Path $VMISO -Verbose
    Start-VM -VMName $VMName

    $VM = Get-VM -Name $VMName
    while ($VM.State -ne "off")
    { 
        write-host "The VM is still running" 
        sleep 20 
    }

    Remove-VM -Name $VMName -Force
    Remove-Item -Recurse -Force D:\VMs\$VMName

$i++
}
while ($i -le $NumberOfVMs)

 

/ Johan


More ...

Viewing all articles
Browse latest Browse all 168

Trending Articles