To run some Tests, I needed to create a bunch of different hosts, and I decided that I want to have new ones and no clones.
I just install a lot of throw-away hosts to run some update Tests (new Windows 10 Build), and I install them customized, so no clones and no automated setup.
Here is a quick script that helped me a lot to create all the Hyper-V Hosts for my Tests:
<#
.SYNOPSIS
Create a simple Windows 10 VM
.DESCRIPTION
Create a simple Windows 10 VM for my Test-LAB
.PARAMETER Client
Client Name
.PARAMETER Path
Wher to create the new Disk Image?
Default is: D:\Hyper-V\Virtual Hard Disks\
.PARAMETER DiskSize
Size of the new Disk in GB?
Default is 100
.PARAMETER StartMem
Memory Size in GB?
Deafult is: 2
.PARAMETER VSwitch
Hyper-V Switch to use?
Default is: EXT (my external LAB Switch)
.PARAMETER Generation
Hyper-V VM Generation?
The default is: 2
.PARAMETER MaxMem
Max RAM Size in MegaByte?
The default is: 3072
.PARAMETER Enterprise
Use Enterprise Edition?
The default is: NO (Then the PRO Image is used)
.EXAMPLE
PS C:\> win10vm.ps1 -Client 'LABWIN10V01'
Create the new VM LABWIN10V01 with the Default settings
.NOTES
TODO: Merge this with my existsing Clone Script.
TODO: Add the other Switches from the LAB Server
#>
param
(
[Parameter(Mandatory = $true,
Position = 1,
HelpMessage = 'Client Name')]
[ValidateNotNullOrEmpty()]
[string]
$Client,
[ValidateNotNullOrEmpty()]
[string]
$Path = 'D:\Hyper-V\Virtual Hard Disks\',
[ValidateNotNullOrEmpty()]
[int]
$DiskSize = 100,
[ValidateNotNullOrEmpty()]
[int]
$StartMem = 2,
[ValidateNotNullOrEmpty()]
[String]
$VSwitch = 'EXT',
[ValidateNotNullOrEmpty()]
[int]
$Generation = 2,
[int]
$MaxMem = 3072,
[switch]
$Enterprise
)
# Where to create the Disk
$Target = $Path + $Client + '.vhdx'
# Create the Disk
$DiskImageSize = ($DiskSize * 1GB)
$null = (New-VHD -Path $Target -Fixed -SizeBytes $DiskImageSize)
# Create the VM, without a Disk. We attach the new disk later
$VMStartupMemeory = ($StartMem * 1GB)
$null = (New-VM -Name $Client -MemoryStartupBytes $VMStartupMemeory -NoVHD -SwitchName $VSwitch -Generation $Generation)
# Set the Memory settings
$VMMaximumBytes = ($MaxMem * 1MB)
$null = (Set-VMMemory -VMName $Client -DynamicMemoryEnabled $true -MaximumBytes $VMMaximumBytes)
# Attach the new Disk
$null = (Add-VMHardDiskDrive -VMName $Client -Path $Target)
# What kind of Windows 10 do we deploy here?
if ($Enterprise)
{
$null = (Add-VMDvdDrive -VMName $Client -Path 'C:\ISO\SW_DVD5_WIN_ENT_10_1511_64BIT_English_MLF_X20-82288.ISO')
}
else
{
$null = (Add-VMDvdDrive -VMName $Client -Path 'C:\ISO\SW_DVD5_Win_Pro_10_1511_64BIT_English_MLF_X20-82416.ISO')
}
# Get the Adapter, Disk, DVD Settings
$network = (Get-VMNetworkAdapter -VMName $Client)
$vhd = (Get-VMHardDiskDrive -VMName $Client)
$dvd = (Get-VMDvdDrive -VMName $Client)
# Set the default Boot order
$null = (Set-VMFirmware -VMName $Client -BootOrder $vhd, $dvd, $network)
# Boot from the DVD on the 1st boot
$null = (Set-VMFirmware -VMName $Client -FirstBootDevice $dvd)
Feel free to improve it on GitHub!