{"id":2721,"date":"2013-10-16T00:01:00","date_gmt":"2013-10-16T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/10\/16\/recovering-virtual-machines-in-hyper-v-server-2012-r2-part-3\/"},"modified":"2013-10-16T00:01:00","modified_gmt":"2013-10-16T00:01:00","slug":"recovering-virtual-machines-in-hyper-v-server-2012-r2-part-3","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/recovering-virtual-machines-in-hyper-v-server-2012-r2-part-3\/","title":{"rendered":"Recovering Virtual Machines in Hyper-V Server 2012 R2: Part 3"},"content":{"rendered":"<p><strong style=\"font-size: 12px\">Summary<\/strong><span style=\"font-size: 12px\">: Re-create network switches by using only Windows PowerShell.<\/span><\/p>\n<p align=\"left\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/>&nbsp;Hey, Scripting Guy!<\/p>\n<p>As part of our continuing disaster recovery tests, my organization would like to know if it is possible to re-create the Hyper-V virtual switches in an isolated location without using the GUI?<\/p>\n<p>&mdash;SH<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/>&nbsp;Hello SH,<\/p>\n<p>Honorary Scripting Guy, Sean Kearney here&mdash;filling in for our good friend Ed. I think he&rsquo;s untangling some old VBScript scripts he found in the back room.<\/p>\n<p style=\"padding-left: 30px\"><strong>Note<\/strong>&nbsp;&nbsp;This is the third post in a series. To review, see:<\/p>\n<ul>\n<li><a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/10\/14\/recovering-virtual-machines-in-hyper-v-server-2012-r2-part-1.aspx\" target=\"_blank\">Recovering Virtual Machines in Hyper-V Server 2012 R2: Part 1<\/a><\/li>\n<li><a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/10\/15\/recovering-virtual-machines-in-hyper-v-server-2012-r2-part-2.aspx\" target=\"_blank\">Recovering Virtual Machines in Hyper-V Server 2012 R2: Part 2<\/a><\/li>\n<\/ul>\n<p>Would it surprise you that the answer to your question is, &ldquo;Yes, YES, and ab-so-JellyBaby-lutely YES!&rdquo;<\/p>\n<p>Last time, we found a virtual machine that we brought to our Hyper-V box called <strong>CONTOSOVM1<\/strong> and it was missing the virtual switch called <strong>PublicNetwork<\/strong>.<\/p>\n<p>I can get this issue patched up by simply using the <strong>New-VMSwitch<\/strong> cmdlet to create a virtual switch on a private network:<\/p>\n<p style=\"padding-left: 30px\">NEW-VMSWITCH &ndash;name &lsquo;PublicNetwork&rsquo; &ndash;SwitchType Private<\/p>\n<p>All this will do is allow us to import the virtual machine and start it. It&rsquo;s not very useful, is it? With a name like <strong>PublicNetwork<\/strong>, I would think that it was probably publicly accessible?<\/p>\n<p>Most smart Administrators create their virtual networks with names that make sense, such as:<\/p>\n<ul>\n<li>&ldquo;DeveloperLan&rdquo;<\/li>\n<li>&ldquo;DMZ&rdquo;<\/li>\n<li>&ldquo;Production&rdquo;<\/li>\n<\/ul>\n<p>And not names like &ldquo;The Land of Bumble Bees and Flying Chickens.&rdquo; (If you do this, you have to clearly document why you chose that name and what purpose it serves.)<\/p>\n<p>So to make this useful to the rest of the network world, we need to know where to attach this switch. If you&rsquo;re putting together things from scratch, you&rsquo;ll need some knowns.<\/p>\n<p>First let&rsquo;s ensure that the only wire attached is the one you want to connect to and that it is physically attached to the back of the Hyper-V box. Then we can run one of the newer cmdlets to see which network adapters are live and attached (ideally, only the one):<\/p>\n<p style=\"padding-left: 30px\">GET-NETADAPTER<\/p>\n<p>This will show us all the network adapters on the computer in question and their status (up\/down, MAC address)<\/p>\n<p>Here&rsquo;s info about my simple box with one detached network adapter:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6746.1.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6746.1.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>To connect the virtual switch to a real network adapter, you need to know its descriptive name in Windows. That&rsquo;s shown in the column on the left called <strong>Name<\/strong> when you access <strong>Get-NetAdapter<\/strong>.<\/p>\n<p>If you know the name of the switch and the name of the virtual network that you want to create, use <strong>New-VMSwitch<\/strong>. The most typical scenario is to create the switch and not share it with the management operating system:<\/p>\n<p style=\"padding-left: 30px\">NEW-VMSwitch &ndash;NetAdapterName &lsquo;Ethernet&rsquo; &ndash;Name &lsquo;PublicNetwork&rsquo;<\/p>\n<p>Or if you have a smaller environment, and you need to run both off the same network adapter, use:<\/p>\n<p style=\"padding-left: 30px\">NEW-VMSwitch &ndash;NetAdapterName &lsquo;Ethernet&rsquo; &ndash;Name &lsquo;PublicNetwork&rsquo; &ndash;AllowManagementOS $TRUE<\/p>\n<p>To determine which card you should attach to (remember I suggested only having the network wire you need attached?), check the <strong>Status<\/strong> of the card, which should not be <strong>Disconnected<\/strong>.<\/p>\n<p style=\"padding-left: 30px\">&hellip;of course, unless you&rsquo;re like me, typing this blog post on my laptop.<\/p>\n<p>If you already have a switch created (like the <strong>Private<\/strong> one we created earlier), you can connect it to the network adapter by using this command:<\/p>\n<p style=\"padding-left: 30px\">SET-VMSwitch &ndash;Name &lsquo;PublicNetwork&rsquo; &ndash;NetAdapterName &lsquo;Ethernet&rsquo; &ndash;AllowManagementOS $FALSE<\/p>\n<p>So now the tricky part is out of the way (of course, presuming your network team has provisioned the back-end switches and routing). Tomorrow we&rsquo;ll see about actually getting these virtual machines imported and operational in the Hyper-V environment.<\/p>\n<p>I invite you to follow the Scripting Guys 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 <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>Sean Kearney<\/strong>, Honorary Scripting Guy and Windows PowerShell MVP&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Re-create network switches by using only Windows PowerShell. &nbsp;Hey, Scripting Guy! As part of our continuing disaster recovery tests, my organization would like to know if it is possible to re-create the Hyper-V virtual switches in an isolated location without using the GUI? &mdash;SH &nbsp;Hello SH, Honorary Scripting Guy, Sean Kearney here&mdash;filling in for [&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-2721","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: Re-create network switches by using only Windows PowerShell. &nbsp;Hey, Scripting Guy! As part of our continuing disaster recovery tests, my organization would like to know if it is possible to re-create the Hyper-V virtual switches in an isolated location without using the GUI? &mdash;SH &nbsp;Hello SH, Honorary Scripting Guy, Sean Kearney here&mdash;filling in for [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2721","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=2721"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2721\/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=2721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=2721"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=2721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}