anyweb 480 Posted August 5, 2017 Report post Posted August 5, 2017 Introduction Update: This script was updated 2017/11/10 with several new abilities to customize most of what you can define in the Virtual Machine settings. This is an extremely quick post to help you create Hyper-V virtual machines using PowerShell. The script assumes you've already installed the Hyper-V feature in Windows. You can define a bunch of variables *highlighted in red below* such as type of Checkpoint, or Memory or CPU settings, to define how your Virtual Machines are created, The script prompts you for three inputs: Virtual Machine name Virtual Switch Name Generation type (Gen1=legacy, Gen 2=UEFI) Here's a screenshot of the script in action: And after running you can see the Virtual Machine properties match what you specified (Gen 2, switch name, cpu settings and so on...) and the New Virtual Switch is created (if it didn't already exist) that's it, have fun. Downloads You can download a copy of the script here. Create HyperV VM2.ps1 Quote Share this post Link to post Share on other sites
KenG 0 Posted October 19, 2018 Report post Posted October 19, 2018 Hi guys, Last night, I was rebuilding my labs and figured out that we could improve the script to be fully automated. As I'm using differencing disks, I wanted to add support for that. If you would like to know more about differencing disks and how to use them, please reach out and I will be happy to help! Let's start with some variables that I added and/or modified to get this thing started. With the $scriptPath variable, I let the script know in which folder it is located. That make things easy to import my csv file. $scriptPath = split-path -parent $MyInvocation.MyCommand.Path $Names = Import-csv $scriptPath\ServerNames.csv The $ParentDisk variable is a hardcoded link to the Parent Disk used for differencing. $ParentDisk = "G:\Keduco\BaseDisk\W2K16_Parent.vhdx" The variables below are changed from Read-Host to a hardcoded value. TIP: It would be even more clean to put the variables below in the csv file as well. 😉 $SwitchName = "Keduco - VLAN1 - 192.168.1.x" $Generation = "2" Now that we have set all our variables, it's time to import the csv file and fill the variable $Name Once our $Name variable is set, we need to focus on the real job... Creating our VMs. That's where I changed things a little bit. I reversed the check dir to store the VM procedure, this because it breaks if the folder allready exist. If we check if the folder is missing, it will first create the Folder and the VM. Does the folder exist, it will just skip and continue with the rest of the VMs. So you can easely add or remove VMs from your csv input file, you can re-run the script as many times as you want, cause it will skip what is created and create what is added to your csv file. I'm sure that you can still improve the script a lot, I mean using a csv to create different types of VMs based on different switches, different generations etc... I created a zip file with the modified script and csv file. Feel free to reach out for help if needed! Best Regards, Ken CreateVMs.zip Quote Share this post Link to post Share on other sites
dfgdf 0 Posted March 30 Report post Posted March 30 . Quote Share this post Link to post Share on other sites