Skip to content

Instantly share code, notes, and snippets.

@jhochwald jhochwald/win10vm.ps1
Last active Nov 12, 2016

Embed
What would you like to do?
PowerShell Script to create a simple Windows 10 VM in my Hyper-V LAB
<#
.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)
@jhochwald

This comment has been minimized.

Copy link
Owner Author

commented Nov 12, 2016

TODO: Merge this with my existsing Clone Script.
TODO: Add the other Switches from the LAB Server

@jhochwald

This comment has been minimized.

Copy link
Owner Author

commented Nov 12, 2016

I use this to create fresh Windows Test Clients in my Hyper-V Lab.
This creates a full Client: I use linked clones only for quick Software Tests! For real Tests I use this... More Disk Space, but complete clean approach :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.