Creating a new lab for practicing the 70-740 Windows 2016 Exam.

It’s essential to have a good lab for testing different scenarios with different features of Windows 2016. Doing this usually requires lots of pointing and clicking, downloading, and wasting time doing repetitious things. Saving this time to use for more preparing for the exam can be solved with a little knowledge of Powershell.
After hosing my lab that was created a few days ago, I decided it would be advantageous to write a small script that utilizes all the cool commands already included in my Windows 10 Professional computer. Here’s is what I came up with.
# Description: Takes user’s input of how many VMs and switchname, then creates VMs with 2016 Server ISO.
# VMs are Generation 2 by default
# Change drive size in command “New-VHD”
# Created by: John Plane, 7/2018
# Troubleshooting: Please confirm you are using a compatible version of Windows 10 that supports all these Powershell commands. Obviously Hyper-V will need to be installed. Check the paths and confirm they exist, I didn’t setup any check for prerequisites, so it’s easy for this to fail without warning.
write-host “Enter number of VMs to create?:”
$number = read-host
write-host “Enter size of drives?:”
$drivesize = read-host
write-host “Enter switch name?:”
$switchname = read-host
new-vmswitch -Name $switchname -switchtype internal
$drivenames = “data”,”cluster”,”boot”
$numbers = 1..$number
foreach ($i in $numbers)
{
new-vm -name 2016-lab$i -generation 2 -path d:\vm\2016\2016-lab$i
Add-VMDvdDrive -VMName 2016-lab$i -path “D:\ISO\Windows_Server_2016_Datacenter_EVAL_en-us_14393_refresh.ISO”
Connect-VMNetworkAdapter -VMName 2016-lab$i -SwitchName $switchname
foreach ($z in $drivenames)
{
new-vhd d:\vm\2016\2016-lab$i\$z$i.vhdx -SizeBytes 10GB -dynamic
add-vmharddiskdrive -vmname 2016-lab$i -path d:\vm\2016\2016-lab$i\$z$i.vhdx }
}
Good luck and keep learning!