The Deployment Bunny

OS Deployment, Virtualization, Microsoft based Infrastructure…

  • Archives

  • Meta

Posts Tagged ‘VMs’

PowerShell is King – Create the “missing” VM on all the lab machines

Posted by Mikael Nystrom on July 9, 2014

Lets assume that you are running a class and suddenly someone raise the hand and say “I’m missing one of the VMs…” That is far from god, but wait a minute, what about PowerShell to the rescue?, of course, so here it is:


Code snip below:

$servers = 1..21 | ForEach-Object {
“VIAMONSTRA{0:D3}” -f $_

foreach ($Server in $Servers)
Invoke-Command -ComputerName $Server -ScriptBlock {
$VMName = “FS01”
$VMMemory = 2048MB
$VMDiskSize = 60GB
$VMNetwork = “Internal”
$VMLocation = “C:\VMs”
New-VM -Name $VMName -Generation 2 -MemoryStartupBytes $VMMemory -SwitchName $VMNetwork -Path $VMLocation -NoVHD | Out-Null
New-VHD -Path “$VMLocation\$VMName\Virtual Hard Disks\$VMName-Disk1.vhdx” -SizeBytes $VMDiskSize | Out-Null
Add-VMHardDiskDrive -VMName $VMName -Path “$VMLocation\$VMName\Virtual Hard Disks\$VMName-Disk1.vhdx” | Out-Null


Posted in Hyper-V, PowerShell | Tagged: , , | Leave a Comment »