{"id":3614,"date":"2013-05-17T00:01:00","date_gmt":"2013-05-17T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/05\/17\/change-virtual-machine-network-configuration-with-powershell\/"},"modified":"2013-05-17T00:01:00","modified_gmt":"2013-05-17T00:01:00","slug":"change-virtual-machine-network-configuration-with-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/change-virtual-machine-network-configuration-with-powershell\/","title":{"rendered":"Change Virtual Machine Network Configuration with PowerShell"},"content":{"rendered":"<p><strong style=\"font-size: 12px\">Summary<\/strong><span style=\"font-size: 12px\">: Learn how to use Windows PowerShell to change the virtual machine network configuration in Windows Server 2012.<\/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 <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 <a href=\"http:\/\/blogs.technet.comhttps:\/\/devblogs.microsoft.com\/scripting\/honorary-scripting-guy-award-recipients-announced\/\" target=\"_blank\">an Honorary Scripting Guy.<\/a> Sean has been selected to present sessions called <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> at TechEd NA and TechEd Europe this year. In his free time, Sean has written several blog posts about Hyper-V and some other cool stuff, and for a few weeks, Sean will be the designated guest blogger on Fridays. Take it away Sean&hellip;<\/p>\n<p>The other weekend I had a pile of virtual machines on our Windows Server 2012 with Hyper-V box. We had created a new network configuration with a &ldquo;teamed lan&rdquo; that we wanted to take advantage of.<\/p>\n<p>My co-worker and System Center mentor, Brad, looked over, &ldquo;Sean, can you spend the afternoon and reconfigure the virtual machines to connect to the newly programmed Hyper-V network?&rdquo;<\/p>\n<p>I stared at him as if he just gave birth to a bag of corn chips. &ldquo;Huh? An hour? I&rsquo;ll bet you that I can do it in less than five minutes!&rdquo;<\/p>\n<p>Knowing that I know Windows Powershell, Brad was intrigued, &ldquo;Prove it!&rdquo;<\/p>\n<p>I popped into the environment and ran the following cmdlet to see the names of the switches.<\/p>\n<p style=\"padding-left: 30px\">GET-VMSWITCH<\/p>\n<p>This produced some useful output in the Windows Powershell console&mdash;showing me all of the network switch names and configurations.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2783.hsg-5-17-13-1.png\"><img decoding=\"async\" style=\"border: 0px currentColor\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2783.hsg-5-17-13-1.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Now my challenge was to know which was the new and which was the old setup. I could look through the GUI console; but with Windows Powershell, I could have it tell me the same thing.&nbsp;<\/p>\n<p>I pulled down the list of virtual machines with <strong>Get-VM<\/strong> and used a new cmdlet from Hyper-V, <strong>Get-VMNetworkAdapter<\/strong>. This cmdlet will show me the configuration of the network adapters within a virtual machine.<\/p>\n<p style=\"padding-left: 30px\">GET-VM | GET-VMNetworkAdapter<\/p>\n<\/p>\n<p>By looking at the list, I could see the old switch configuration that I was using was named &ldquo;Hyper-V-Lan1.&rdquo;<\/p>\n<p>Making the change was so easy that my friend Brad&rsquo;s eyes popped open just like Jim Carrey in &ldquo;The Mask.&rdquo; &nbsp;I simply invoked another new built-in cmdlet, <strong>Connect-VMNetworkAdapter<\/strong>. All I had to do was plug in the new network name I got from <strong>Get-VMSwitch<\/strong>.<\/p>\n<p style=\"padding-left: 30px\">GET-VM | GET-VMNetworkAdapter | Connect-VMNetworkAdapter &ndash;Switchname &lsquo;New-cool-Hyper-V-Lan&rsquo;<\/p>\n<p>I looked up with a big goofy grin on my face, &ldquo;Done! I&rsquo;ll see you tomorrow.&rdquo;&nbsp;<\/p>\n<p>Brad blinked, &ldquo;Tomorrow?&rdquo;<\/p>\n<p>&ldquo;You just asked me to spend the afternoon. I did. I just spent it in a more efficient method!&rdquo;<\/p>\n<p>The best part is knowing this: I could have just as easily switched the configuration on thousands of machines in a very similar time frame.<\/p>\n<p>Feel the Power within you.<\/p>\n<p>~Sean<br \/> The Energized Tech<\/p>\n<p>Way cool stuff, Sean. Join Sean next week for more Windows PowerShell and Hyper-V stuff. Join me tomorrow for the Weekend Scripter.<\/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: Learn how to use Windows PowerShell to change the virtual machine network configuration in Windows Server 2012. 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 [&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,130,45,368],"class_list":["post-3614","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-servers","tag-windows-powershell","tag-windows-server-2012"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to use Windows PowerShell to change the virtual machine network configuration in Windows Server 2012. 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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3614","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=3614"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3614\/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=3614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=3614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=3614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}