#Variables, change Settings where needed.
$Server2012 = "F:\Hyper-V Labs\Windows.Server.2012.vhdx"
$ServerCore2012 = "F:\Hyper-V Labs\Windows.Server.2012.Core.vhdx"
$Windows10Pro = "F:\Hyper-V Labs\Windows.10.Pro.vhdx"
$VHDPath = "D:\Hyper-V\Virtual Hard Disks\"
$NetWork = "HomeLab"
function Show-Menu { param ( [string]$Title = 'Windows Hyper-V Virtual Machine Creation Tool' ) cls Write-Host "" Write-Host "================ $Title ================" Write-Host
Write-Host "1: Press '1' Create a Server 2012r2 VM"
Write-Host "2: Press '2' Create a Server 2012r2 Core VM"
Write-Host "3: Press '3' Create a Windows 10 Pro VM"
Write-Host "4: Press '4' Create Ubuntu Server VM"
Write-Host "Q: Press 'Q' to quit."
Write-Host ""
}
do { Show-Menu $input = Read-Host "Please make a selection" switch ($input) { '1' { cls DO { Write-Host "" Write-Host "################### Windows Server 2012r2 VM ###################" Write-Host ""
$VMName = Read-Host -Prompt "Input your VM name (Blank=finish)"
If ($VMName -eq "") {
Write-Verbose "VMs created"
break
}
ELSE
{
#Create Differencing VHD pointing to Homelab-Server2012r2
New-VHD -ParentPath "$Server2012" -Path "$VHDPath\$VMName.vhdx" -Differencing
#Create New VMs
New-VM -Name $VMName -MemoryStartupBytes 1024MB -Generation 2 -SwitchName $NetWork -VHDPath "$VHDPath\$VMName.vhdx"
}
}
While ($true)
} '2' {
cls
DO {
Write-Host ""
Write-Host "################### Windows Server 2012r2 Core VM ###################"
Write-Host ""
$VMName = Read-Host -Prompt "Input your VM name (Blank=finish)"
If ($VMName -eq "") {
Write-Verbose "VMs created"
break
}
ELSE
{
#Create Differencing VHD
New-VHD -ParentPath "$ServerCore2012" -Path "$VHDPath\$VMName.vhdx" -Differencing
#Create New VMs
New-VM -Name $VMName -MemoryStartupBytes 1024MB -Generation 2 -SwitchName $NetWork -VHDPath "$VHDPath\$VMName.vhdx"
}
}
While ($true)
} '3' {
cls
DO {
Write-Host ""
Write-Host "################### Windows 10 Pro VM ###################"
Write-Host ""
$VMName = Read-Host -Prompt "Input your VM name (Blank=finish)"
If ($VMName -eq "") {
Write-Verbose "VMs created"
break
}
ELSE
{
#Create Differencing VHD pointing to Homelab-Server2012r2
New-VHD -ParentPath "$Windows10Pro" -Path "$VHDPath\$VMName.vhdx" -Differencing
#Create New VMs
New-VM -Name $VMName -MemoryStartupBytes 1024MB -Generation 2 -SwitchName $NetWork -VHDPath "$VHDPath\$VMName.vhdx"
}
}
While ($true)
} '4' {
cls
DO {
Write-Host ""
Write-Host "################### UBUNTU Server VM ###################"
Write-Host ""
$VMName = Read-Host -Prompt "Input your VM name (Blank=finish)"
If ($VMName -eq "") {
Write-Verbose "VMs created"
break
}
ELSE
{
#Create Differencing VHD pointing to Homelab-Server2012r2
New-VHD -Dynamic $VHDPath\$VMName.vhdx
#Create New VMs
New-VM -Name $VMName -MemoryStartupBytes 1024MB -Generation 1 -SwitchName $NetWork -VHDPath "$VHDPath\$VMName.vhdx"
}
}
While ($true)
} 'q' {
cls
return
}
}
pause
} until ($input -eq 'q')