{"id":13808,"date":"2012-11-20T11:49:25","date_gmt":"2012-11-20T11:49:25","guid":{"rendered":"https:\/\/aidanfinn.com\/?p=13808"},"modified":"2012-11-20T11:49:25","modified_gmt":"2012-11-20T11:49:25","slug":"create-lots-of-hyper-v-virtual-machines-from-a-csv-file-using-powershell","status":"publish","type":"post","link":"https:\/\/aidanfinn.com\/?p=13808","title":{"rendered":"Create Lots Of Hyper-V Virtual Machines From A CSV File Using PowerShell"},"content":{"rendered":"<p>A friend of mine works for a software company, looking after a test rig for one of their product families.\u00a0 The test rig is based on Hyper-V, and they have to frequently provision <em>lots<\/em> of virtual machines to test new products.\u00a0 We were chatting about how they do this a few weeks ago and I thought \u201cI bet I could do that using PowerShell, and I bet I could create a very nice solution too\u201d.\u00a0 What I wanted: A PowerShell script that would make lots of Windows Server 2012 (WS2012) Hyper-V VMs from a comma separated values (CSV) file.\u00a0 I also thought that this would be a great demonstration of PowerShell during WS2012 Hyper-V demos that I\u2019m frequently doing.<\/p>\n<p>So I put some work into it.\u00a0 The concept is based on a previous <a href=\"https:\/\/aidanfinn.com\/?p=12190\" target=\"_blank\">script<\/a> that I wrote, but I took it to the Nth degree.<\/p>\n<p>Here\u2019s how my script works:<\/p>\n<ol>\n<li>You create a CSV file that specifies the configuration of each VM (1 row per VM).<\/li>\n<li>You edit the script to read that file (easy change near the top)<\/li>\n<li>You run the script<\/li>\n<li>The results are recorded in a log file that you specify in the script (a second easy change near the top)<\/li>\n<\/ol>\n<p>I\u2019ve put instructions in the <a href=\"https:\/\/aidanfinn.com\/Downloads\/VMsFromCSV.zip\" target=\"_blank\">script<\/a>.\u00a0 I\u2019ve also supplied a sample CSV file in the zip file to show three different types of VHDX creation.<\/p>\n<p>The script allows you to specify the following in the CSV:<\/p>\n<ul>\n<li>Storage location of the VM<\/li>\n<li>Name of the VM<\/li>\n<li>Processor count<\/li>\n<li>Virtual memory, including Dynamic Memory if you want<\/li>\n<li>VHDX type and configuration, including Fixed, Dynamic, and Differencing<\/li>\n<\/ul>\n<p>So how could you use the script?<\/p>\n<ul>\n<li>Maybe you want to create lots of pooled or personal VMs<\/li>\n<li>Possibly you need to deploy a demo lab with lots of VMs<\/li>\n<li>Maybe you are like my friend, working in a large software test environment, and you\u2019d like to deploy lots of VMs, and you\u2019d like to be able to vary the specification and build of those VMs<\/li>\n<\/ul>\n<p>There\u2019s nothing to stop you from editing the script and either adding\/removing functionality.\u00a0 If you find it useful, then go ahead and use it.\u00a0 In fact, if you do use it, then tell me how because I\u2019ll be interested.<\/p>\n<p><em>This script is not supported by me.\u00a0 Use and\/or modify the script at your own risk.<\/em><\/p>\n<p>Please note that this script is mine and you may not re-share it without my permission.\u00a0 Please link to this blog post instead.<\/p>\n<p>You can download the script and sample CSV file from <a href=\"https:\/\/aidanfinn.com\/Downloads\/VMsFromCSV.zip\" target=\"_blank\">here<\/a>.<\/p>\n<p>Possible improvements:<\/p>\n<ul>\n<li>Add remote host functionality<\/li>\n<li>Add cluster functionality<\/li>\n<li>Start VMs<\/li>\n<\/ul>\n<p>This information has been brought to you by <a href=\"http:\/\/www.amazon.com\/Windows-Server-Hyper-V-Installation-Configuration\/dp\/1118486498%3FSubscriptionId%3DAKIAIJ5WNI7ZSH7W4OXA%26tag%3Dafm0c-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D1118486498\">Windows Server 2012 Hyper-V Installation and Configuration Guide<\/a> (available on pre-order on Amazon) where you\u2019ll find lots of PowerShell like in this script:<\/p>\n<p><a href=\"http:\/\/www.amazon.com\/Windows-Server-Hyper-V-Installation-Configuration\/dp\/1118486498%3FSubscriptionId%3DAKIAIJ5WNI7ZSH7W4OXA%26tag%3Dafm0c-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D1118486498\"><img loading=\"lazy\" decoding=\"async\" style=\"float: none; margin-left: auto; display: block; margin-right: auto;\" title=\"image\" src=\"https:\/\/aidanfinn.com\/wp-content\/uploads\/2012\/09\/image_thumb19.png\" border=\"0\" alt=\"image\" width=\"196\" height=\"244\" \/><\/a><\/p>\n<div id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:31d3bd7d-7e8e-44fa-992a-93c803d81922\" class=\"wlWriterEditableSmartContent\" style=\"float: none; margin: 0px; display: inline; padding: 0px;\">Technorati Tags: <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/Windows+Server+2012\">Windows Server 2012<\/a>,<a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/Hyper-V\">Hyper-V<\/a>,<a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/Virtualisation\">Virtualisation<\/a>,<a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/PowerShell\">PowerShell<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>A friend of mine works for a software company, looking after a test rig for one of their product families.\u00a0 The test rig is based on Hyper-V, and they have to frequently provision lots of virtual machines to test new products.\u00a0 We were chatting about how they do this a few weeks ago and I &hellip; <a href=\"https:\/\/aidanfinn.com\/?p=13808\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Create Lots Of Hyper-V Virtual Machines From A CSV File Using PowerShell&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[20],"tags":[181,87,195,118],"class_list":["post-13808","post","type-post","status-publish","format-standard","hentry","category-hyper-v","tag-hyper-v","tag-powershell","tag-virtualisation","tag-windows-server-2012"],"aioseo_notices":[],"jetpack_featured_media_url":"","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/posts\/13808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13808"}],"version-history":[{"count":0,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=\/wp\/v2\/posts\/13808\/revisions"}],"wp:attachment":[{"href":"https:\/\/aidanfinn.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aidanfinn.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}