Wrote this a few days back to script spinning up VMs to test in lab. Not putting on TechNet, but if you use it and have recommendations, please post in comments. Using the lab build from @expta, I was able to get 6 VMs in about 8 minutes ready to go!
$vmpath = "c:\virtual machines"
$vmswitch = "LAN"
$templatepath = "c:\templates\w2012r2-template-sysprepped.vhdx"
$servers = ("fe1","fe2","fe3")
Import-Module BitsTransfer
$servers | ForEach {
Write-Warning -Message "Copying VHDX and setting it to RW for $_"
Start-BitsTransfer -Source $templatepath -Destination $vmpath\$_.vhdx -Description "Copying $_ VHD" -DisplayName "Copying $_ VHD"
attrib -r $vmpath\$_.vhdx # Recommend your template being RO so you don't lose it!
Write-Warning -Message "Creating and Starting Virtual Machine for $_"
New-VM -Name $_ -VHDPath "$vmpath\$_.vhdx" -MemoryStartupBytes 2GB -generation 2 -SwitchName $vmswitch | Out-Null
Start-VM -Name $_ | Out-Null
}
No comments:
Post a Comment