Creating multiple Hyper-V virtual machines using Hyper-V manager is not a quick method. The quickest and time-saving method is to create them via Windows PowerShell. This tutorial has been written to show you how to create three Hyper-V virtual machines with a PowerShell script.

Create Multiple Hyper-V Virtual Machines Using PowerShell

Step 1. Open notepad editor and copy/paste the following script and save the file with .ps1 extension

1..3 | % {

$VMName = "TestWS2012-VM0$_"

Write-Host "Create VM $VMName"

New-VM -Name $VMName -MemoryStartupBytes 2GB -SwitchName VMNET -Path <a href="file://\\sofs01\Share01\&quot; data-mce-href=">\\sofs01\Share01\</a>

Write-Host "Copy VHD..."

Copy-item '\\sofs01\Share01\ISOs\Disk\Virtual Hard Disks' -Destination "\\sofs01\Share01\$VMName" -Recurse

Write-Host "Attach VHD..."

Add-VMHardDiskDrive -VMName $VMName -ControllerType IDE -ControllerNumber 0 -Path <a href="file://\\sofs01\Share01\$VMName\Virtual Hard Disks\WS2012.vhdx">\\sofs01\Share01\$VMName\Virtual Hard Disks\WS2012.vhdx</a>

Write-Host "Configure Virtual Machine..."

Set-VM -Name $VMName -DynamicMemory -MemoryMaximumBytes 4GB -MemoryMinimumBytes 512MB -MemoryStartupBytes 1GB -ProcessorCount 2

Write-Host "Startup Virtual Machine: $VMName..."

Start-VM -Name $VMName


Step 2. Open PowerShell with elevated privileges and execute the script from step 1.
How to Create Multiple Hyper-V Virtual Machines Using PowerShell

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *