{"id":3366,"date":"2013-06-21T00:01:00","date_gmt":"2013-06-21T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/06\/21\/create-a-new-virtual-machine-with-powershell-part-2\/"},"modified":"2013-06-21T00:01:00","modified_gmt":"2013-06-21T00:01:00","slug":"create-a-new-virtual-machine-with-powershell-part-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/create-a-new-virtual-machine-with-powershell-part-2\/","title":{"rendered":"Create a New Virtual Machine with PowerShell: Part 2"},"content":{"rendered":"<p><strong style=\"font-size: 12px\">Summary<\/strong><span style=\"font-size: 12px\">: Microsoft PowerShell MVP and honorary Scripting Guy, Sean Kearney, continues his series about using Windows PowerShell to&nbsp;create a virtual machine.<\/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>To read Part 1 of this 3-part series, please see <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/06\/14\/create-a-new-virtual-machine-with-windows-powershell-part-1.aspx\" target=\"_blank\">Create a New Virtual Machine with Windows PowerShell: Part 1<\/a>.<\/p>\n<p>Here&rsquo;s Sean&hellip;<\/p>\n<p>Brad and I returned from lunch to again look at the message we received after we specified the following cmdlet in Windows Server 2012 with Hyper-V:<\/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>We got this prompt:<\/p>\n<p style=\"padding-left: 30px\">NewVHDSizeBytes:<\/p>\n<p>I looked at the message. &ldquo;It seems to be asking for how large the VHD file should be. From the example of the memory, I think we can just type it in as 60&nbsp;GB.&rdquo;<\/p>\n<p>We typed that and got a different error message:<\/p>\n<p style=\"padding-left: 30px\">Cannot recognize &ldquo;60000MB&rdquo; as a System.UInt64 due to a format error.<\/p>\n<p>I looked up. &ldquo;Ah! A .NET error. I guess it wants us to type 60 GB in long form. If we&rsquo;re going to do that, let&rsquo;s type a single-line command:<\/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 &ndash;NewVHDSizeBytes 6000000000<\/p>\n<p>A moment later, we checked the Hyper-V console and saw a newly created virtual machine.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4442.hsg-6-21-13-1.png\"><img decoding=\"async\" title=\"Image of menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4442.hsg-6-21-13-1.png\" alt=\"Image of menu\" \/><\/a><\/p>\n<p>&ldquo;How did you know the parameter name was <strong>-NewVHDSizeBytes<\/strong>?&rdquo; he asked.<\/p>\n<p>I looked over at Brad. &ldquo;If a parameter is needed and is not specified, Windows PowerShell will show the parameter name and prompt for the needed value. So I knew from experience using Windows PowerShell that if I saw a prompt asking for a value, it would be a parameter for the cmdlet.&rdquo;<\/p>\n<p>Brad looked at me. &ldquo;But what about the CPU cores? What about the network settings? I didn&rsquo;t see anything about those in the cmdlet we entered. How do we deal with that?&rdquo;<\/p>\n<p>&ldquo;Let&rsquo;s see if there are any cmdlets for the virtual machine network adapter,&rdquo; I suggested.<\/p>\n<p style=\"padding-left: 30px\">GET-COMMAND *Network* -module Hyper-V<\/p>\n<p>The results gave us an answer almost immediately. Near the top of the list was the <strong>Add-VMNetworkAdapter<\/strong> cmdlet.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8446.hsg-6-21-13-2.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8446.hsg-6-21-13-2.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Brad quickly typed the cmdlet name to see an example of its use.<\/p>\n<p style=\"padding-left: 30px\">GET-HELP ADD-VMNetworkAdapter &ndash;examples<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4118.hsg-6-21-13-3.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4118.hsg-6-21-13-3.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>He looked up and said, &ldquo;Is it really that easy? Just add the network adapter to the virtual machine? So if I want to call the network adapter to my virtual switch called &lsquo;Hyper-V-Prod1&rsquo; and attach it to the &lsquo;Brad VM SCSM&rsquo; virtual machine, I would type this&hellip;&rdquo;<\/p>\n<p style=\"padding-left: 30px\">ADD-VMNetworkAdapter &ndash;VMName &ldquo;Brad VM SCSM&rdquo; &ndash;Switchname &ldquo;Hyper-V-Prod1&rdquo;<\/p>\n<p>Now to the second task: set the CPU settings. Brad was already at the keyboard figuring it out. &ldquo;So, let&rsquo;s see. I can find a cmdlet that might meet my need for the processor. Let&rsquo;s search.&rdquo;<\/p>\n<p style=\"padding-left: 30px\">GET-COMMAND *Processor* -module Hyper-V<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6862.hsg-6-21-13-4.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6862.hsg-6-21-13-4.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Looking at the available cmdlets for processor settings, it seemed logical to Brad to use <strong>SET-VMProcessor<\/strong> if he wants to SET the virtual machine&rsquo;s settings for the processor. He typed <strong>Get-Help<\/strong> to find examples for its use.<\/p>\n<p style=\"padding-left: 30px\">GET-HELP SET-VMProcessor -examples<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6763.hsg-6-21-13-5.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6763.hsg-6-21-13-5.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>The first example seemed to meet the need. He entered his virtual machine name, &ldquo;Brad VM SCSM&rdquo;, and added a count of 2 virtual CPUs.<\/p>\n<p style=\"padding-left: 30px\">SET-VMProcessor &ndash;VMName &ldquo;Brad VM SCSM&rdquo; &ndash;Count 2<\/p>\n<p>We pulled up the properties of the virtual machine to check the configuration.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3034.hsg-6-21-13-6.png\"><img decoding=\"async\" title=\"Image of menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3034.hsg-6-21-13-6.png\" alt=\"Image of menu\" \/><\/a><\/p>\n<p>A smile crossed Brad&rsquo;s face. &ldquo;How can I make this repeatable for multiple machines?&rdquo;<\/p>\n<p>~Sean<\/p>\n<p>Thank Sean, this is really good stuff. Join Sean next Friday for the exciting conclusion of this series, and 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 PowerShell MVP and honorary Scripting Guy, Sean Kearney, continues his series about using Windows PowerShell to&nbsp;create a virtual machine. 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 [&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-3366","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 PowerShell MVP and honorary Scripting Guy, Sean Kearney, continues his series about using Windows PowerShell to&nbsp;create a virtual machine. 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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3366","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=3366"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3366\/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=3366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=3366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=3366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}