In this blog post I’d like to explain how to create Generation 2 Virtual Machine in few seconds with PowerShell. This .ps1 script is a very simple and you can create just one VM but you can edit it for your needs.
In the last two years on my lectures I noticed that many of attendees don’t understand the basics and also they are ashamed to ask in the front of other attendees. For that reason I want to help them!
This is my way how to create VM. I used PowerShell ISE for the better look
Step 1.
Step 2.
Type command like in the picture below, edit what you need to edit and press Run Script (F5).
### create client generation 2 virtual machine ### New-VM -Name ATDGen2 -Path "C:\Hyper-V" -Generation 2 -SwitchName WiredLan Set-VM -Name ATDGen2 -ProcessorCount 2 -DynamicMemory -MemoryStartupBytes 512MB -MemoryMinimumBytes 512MB -MemoryMaximumBytes 2048MB New-VHD -Dynamic -SizeBytes 37GB -Path "C:\Hyper-V\ATDGen2\VirtualHardDisk\ATDGen2.vhdx" Add-VMHardDiskDrive -VMName ATDGen2 -Path "C:\Hyper-V\ATDGen2\VirtualHardDisk\ATDGen2.vhdx" Add-VMDvdDrive -VMName ATDGen2 -Path "D:\Software\Microsoft\Windows8.1Ent\en_windows_8_1_enterprise_x64_dvd_2791088.iso" Set-VM -Name ATDGen2 -AutomaticStartAction StartIfRunning -AutomaticStopAction ShutDown Start-VM -Name ATDGen2
And voila, in the few seconds VM is created. You will need approximately two minutes for OS installation on SSD. As you can see, VM is Up & Running.
You can expect more fundamental things related to virtualization very soon.
Enjoy the day ;)
Romeo