Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views :

IT with everything IT

Creating Multiple VM’s Using Hyper-V PowerShell


Let’s Improvise our skills at creating the Virtual machines using Hyper-V PowerShell. Think of a scenario that you are building a new Lab environment to test something which you are working on before you implement it on the production environment.

For this case, you may have to create a hell lot of VM’s including the DC’s, Database Servers, DNS, DHCP, your App server Etc…

If you are just looking for a guide to create one Virtual Machine by using PowerShell or GUI, Click here

I have created a simple script to help you to achieve this. Below script thinks that you have a .txt file which contains the VMName list and Creates VM names according to each name which are separated by lines in the .txt file, Add an ISO file for OS Installation,and puts the HDD in to the directory “%User%\Documents\Hyper-V\Virtual Machines\NameOfVM\NameOfVM.VHDX”, Creates a New Private Hyper-V Switch and assigns it to all VM’s.

# This script creates a Multiple VM's Based on the Names file you provided.

#Enter the File path which contains the VM names in a separate Lines
$VMName = Get-Content (Read-Host "Enter the Path of Virtual Machine Names File")

#Enter the ISO File path which contains the Windows Installation files
$ISOpath = Read-Host "Enter the path of the Operating System ISO File"

#Path of the VM HDD file stored
$VMLOC = "$Home\Documents\Hyper-V\Virtural Machines"

#Create a New Private switch and assign it to variable
New-VMSwitch -Name "PrivateNetwork" -SwitchType Private
$VMNet = "PrivateNetwork"

#Create the VM's
Foreach($vm in $VMName) { New-VM -Name $VM -Generation 2 -SwitchName $VMNet 
 New-VHD -Path "$VMLOC\$VM\$vm.vhdx" -Dynamic -SizeBytes 60GB
 ADD-VMHardDiskDrive -VMName $vm -Path "$VMLOC\$VM\$vm.vhdx"
 Set-VM $VM -MemoryMinimumBytes 1GB
 Add-VMDvdDrive -VMName $vm -Path $ISOpath


Leave a Comment

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

This div height required for enabling the sticky sidebar