{"id":3406,"date":"2013-06-14T00:01:00","date_gmt":"2013-06-14T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/06\/14\/create-a-new-virtual-machine-with-powershell-part-1\/"},"modified":"2013-06-14T00:01:00","modified_gmt":"2013-06-14T00:01:00","slug":"create-a-new-virtual-machine-with-powershell-part-1","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/create-a-new-virtual-machine-with-powershell-part-1\/","title":{"rendered":"Create a New Virtual Machine with PowerShell: Part 1"},"content":{"rendered":"<p><strong style=\"font-size: 12px\">Summary<\/strong><span style=\"font-size: 12px\">: Microsoft Windows PowerShell MVP and honorary Scripting Guy, Sean Kearney, begins a three-part series about creating new virtual machines.<\/span><\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. If you are a seasoned Hey, Scripting Guy! Blog reader, you know that the most frequent guest blogger is Sean Kearney. If you are new to the blog, I welcome you, and I encourage you to catch up with&nbsp;<a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/sean+kearney\/\" target=\"_blank\">Sean&rsquo;s previous blogs<\/a>.<\/p>\n<p>Sean is a Windows PowerShell MVP and&nbsp;<a href=\"http:\/\/blogs.technet.comhttps:\/\/devblogs.microsoft.com\/scripting\/honorary-scripting-guy-award-recipients-announced\/\" target=\"_blank\">an Honorary Scripting Guy.<\/a>&nbsp;Sean&rsquo;s session at TechEd NA and TechEd Europe this year is&nbsp;<a href=\"https:\/\/channel9.msdn.com\/Events\/TechEd\/NorthAmerica\/2013\/MDC-B326#fbid=rHDRO4Syj3v\" target=\"_blank\">Integrating with Microsoft System Center 2012 and Windows PowerShell<\/a>. In his free time, Sean has written several blog posts about Hyper-V and some other cool stuff, and for the next few weeks, Sean will be the designated guest blogger on Fridays.<\/p>\n<p>Take it away Sean&hellip;<\/p>\n<p>I felt a little poke on my shoulder the other day. A friend came and asked me how hard it is to create a virtual machine with Windows Powershell and Hyper-V.<\/p>\n<p>I typed in the following cmdlet and walked off.<\/p>\n<p style=\"padding-left: 30px\">NEW-VM<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4530.hsg-6-14-13-1.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4530.hsg-6-14-13-1.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>He blinked and came back to me.&nbsp;<span style=\"font-size: 12px\">&ldquo;OK, smart guy. I see. That created a new BLANK virtual machine called &ldquo;New Virtual Machine&rdquo; with 512 MB of RAM, no hard drive, and unattached to any LAN. Being a little funny today, aren&rsquo;t we?&rdquo;<\/span><\/p>\n<p>I was feeling a bit mischievous at the moment. I&rsquo;m allowed from time-to-time.&nbsp;<span style=\"font-size: 12px\">&ldquo;Well, I did meet your needs. You said &lsquo;create a virtual machine.&rsquo; So how about we define our parameters?&rdquo;<\/span><\/p>\n<p>&ldquo;OK. I would like to see an example of creating a virtual machine with the following configuration:&rdquo;<\/p>\n<p style=\"padding-left: 30px\">Name of &ldquo;Brad VM SCSM&rdquo;<\/p>\n<p style=\"padding-left: 30px\">2 gigabytes of RAM<\/p>\n<p style=\"padding-left: 30px\">60 gigabyte hard drive<\/p>\n<p style=\"padding-left: 30px\">2 CPU cores assigned<\/p>\n<p style=\"padding-left: 30px\">Connected to my virtual network called &ldquo;Hyper-V-Prod1&rdquo;<\/p>\n<p>I smiled and looked across to my friend. &ldquo;No problem. So, from what I&rsquo;ve been showing you about Windows PowerShell, how would you determine the use of this cmdlet?&rdquo;<\/p>\n<p>He looked over. &ldquo;First off, I remember that using <strong>Get-Help<\/strong> should show me the available parameters for the cmdlet.&rdquo;<\/p>\n<p style=\"padding-left: 30px\">GET-HELP NEW-VM<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6165.hsg-6-14-13-2.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6165.hsg-6-14-13-2.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>&ldquo;Then if I need to find examples of the cmdlet in use, I would run the same with the <strong>&ndash;examples<\/strong> parameter.&rdquo;<\/p>\n<p style=\"padding-left: 30px\">GET-HELP NEW-VM -examples<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6278.hsg-6-14-13-3.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6278.hsg-6-14-13-3.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Looking at the information before us, we see that we can at least create a virtual machine with 2 GB of RAM, based on the first example, by using this command:<\/p>\n<p style=\"padding-left: 30px\">NEW-VM &ndash;Name &ldquo;Brad VM SCSM&rdquo; &ndash;MemoryStartupBytes 2048<\/p>\n<p>Brad looked up. &ldquo;Now that should work, but we still need the virtual hard disk in this configuration. From what I see in the second example, we could specify a virtual hard disk if we knew the physical path to place it. I know my VHDs are sitting on Drive E:\\VHD on my Hyper-V host in the lab. So I should just be able to pick a VHD file name that is unique to my virtual machine.&rdquo;<\/p>\n<p style=\"padding-left: 30px\">NEW-VM &ndash;Name &ldquo;Brad VM SCSM&rdquo; &ndash;MemoryStartupBytes 2048 &ndash;NewVHDPath E:\\VHD\\BradVMSCSM-C.VHDX<\/p>\n<p>But when he ran the cmdlet, he got the following prompt:<\/p>\n<p style=\"padding-left: 30px\">NewVHDSizeBytes:<\/p>\n<p>Scratching his head, he looked over. &ldquo;What happened?&rdquo;<\/p>\n<p>I smiled. &ldquo;It was a poorly written example, apparently. Human error. Let&rsquo;s grab lunch first, and then we&rsquo;ll take a look back.&rdquo;<\/p>\n<p>~Sean<\/p>\n<p>Thanks, Sean. This is great, and I cannot wait to see the next two posts. I invite everyone to join me tomorrow for more cool Windows PowerShell stuff.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong><span style=\"font-size: 12px\">&nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Windows PowerShell MVP and honorary Scripting Guy, Sean Kearney, begins a three-part series about creating new virtual machines. Microsoft Scripting Guy, Ed Wilson, is here. If you are a seasoned Hey, Scripting Guy! Blog reader, you know that the most frequent guest blogger is Sean Kearney. If you are new to the blog, [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[56,271,3,154,45],"class_list":["post-3406","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-hyper-v","tag-scripting-guy","tag-sean-kearney","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Windows PowerShell MVP and honorary Scripting Guy, Sean Kearney, begins a three-part series about creating new virtual machines. Microsoft Scripting Guy, Ed Wilson, is here. If you are a seasoned Hey, Scripting Guy! Blog reader, you know that the most frequent guest blogger is Sean Kearney. If you are new to the blog, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=3406"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3406\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=3406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=3406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=3406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}