{"id":1653,"date":"2014-04-07T00:01:00","date_gmt":"2014-04-07T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/04\/07\/windows-server-2012-r2-network-cmdlets-part-1\/"},"modified":"2014-04-07T00:01:00","modified_gmt":"2014-04-07T00:01:00","slug":"windows-server-2012-r2-network-cmdlets-part-1","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/windows-server-2012-r2-network-cmdlets-part-1\/","title":{"rendered":"Windows Server 2012 R2 Network Cmdlets: Part 1"},"content":{"rendered":"<p><b>Summary<\/b>: Discover Windows PowerShell cmdlets and modules in Windows Server&nbsp;2012&nbsp;R2 for networking.<\/p>\n<p><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! I used to use <span>netsh.exe<\/span>&nbsp;to try to automate my server configurations. I can deal with it, but I heard that you can do a lot of this with Windows PowerShell in Windows Server&nbsp;2012&nbsp;R2. Do you know how I figure out which cmdlets to use?<\/p>\n<p>&mdash;BP<\/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 BP,<\/p>\n<p>Honorary Scripting Guy, Sean Kearney, is here. Today kicks off Windows PowerShell Network Week. I&rsquo;m going to introduce a new and better way to manage networking in the Windows Server environment by using the network cmdlets in Windows Server&nbsp;2012&nbsp;R2.<\/p>\n<p>You mentioned netsh.exe. I remember <span>netsh.exe<\/span>. I remember vividly not liking it. You could automate it, but it was difficult to find good examples of everyday use. I had to dig around online.<\/p>\n<p>Having said that, there are scenarios where <span>netsh.exe<\/span>&nbsp;is still used. For example, <span>netsh.exe<\/span>&nbsp;is still one of the ways to list and remove wireless profiles. Pierre Roman from Microsoft Canada showed us this neat trick:<\/p>\n<p style=\"margin-left:30px\">NETSH wlan show profiles<\/p>\n<p>But there is so much more you can now do far easier in networking by using Windows PowerShell in Windows Server&nbsp;2012&nbsp;R2. Whether you are a new IT pro just getting your feet wet or a seasoned field specialist, Windows PowerShell makes the tasks far simpler and more consistent for your network needs.<\/p>\n<p>So let&rsquo;s take a quick look at how many modules are available to us to manage networking needs in Windows Powershell:<\/p>\n<p style=\"margin-left:30px\">Get-Module *NET* -ListAvailable<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5127.1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5127.1.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Eleven modules just sitting there, itching to be used to make your day easier. This week I&rsquo;ll try to touch on some of the more common networking needs and show you how they can be done in the Windows Server&nbsp;2012&nbsp;R2 environment.<\/p>\n<p>That little voice in me is wondering (for trivia&rsquo;s sake), &ldquo;How many cmdlets do we have available.&rdquo;<\/p>\n<p>Oh just for fun, we&rsquo;ll find out:<\/p>\n<p style=\"margin-left:30px\">Get-Command &ndash;Module *NET*<\/p>\n<p>I tried to count them all as they scrolled past me, but even with five espressos, I couldn&rsquo;t read that fast. (No really, I couldn&rsquo;t!) So I let Windows PowerShell do the counting for me:<\/p>\n<p style=\"margin-left:30px\">(Get-Command &ndash;Module *NET* ).count<\/p>\n<p>I had to pick my eyeballs off the ground and wipe them off as I saw the number: 283! I mouthed aloud as a large puddle of drool formed on my desk, &ldquo;Oh, this is going to be a fun week!&rdquo;<\/p>\n<p>So where do we start? Let&rsquo;s do something simple and try to work out physical network adapters. So how would I go about trying to find a cmdlet that might have something do with adapters?<\/p>\n<p>How about a simple <b>Get-Command<\/b> and simply ask!<\/p>\n<p style=\"margin-left:30px\">Get-Command &ndash;Module *NET* -verb GET -noun *Adapter*<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2234.2.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2234.2.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>So it looks like trying to get network adapters is going to be easy. There is a whole pile of cmdlets written for that task alone. In addition, I can see the module names seem to reflect their tasks very well.<\/p>\n<p>What does that mean?<\/p>\n<p>I should be able to look at the module name and determine its purpose easily.<\/p>\n<p>For example, <b>NetAdapter<\/b> handles requests about my network adapters. So perhaps the <b>NetSecurity<\/b> might have something to do with the firewall? I can easily pull down the cmdlets for <b>NetSecurity<\/b> and look:<\/p>\n<p style=\"margin-left:30px\">Get-Command &ndash;Module NetSecurity<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0116.3.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0116.3.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Looks like it does!<\/p>\n<p>All this means that I simply need to think about what I&rsquo;m going to need to do, find the appropriate module, and determine whether I&rsquo;m going to <b>Get<\/b> or <b>Set<\/b> or <b>Remove<\/b> network information. We can plug this into <b>Get-Command<\/b> to suggest the appropriate cmdlets!<\/p>\n<p>BP, come back tomorrow and we&rsquo;ll play with a scenario in which we start to use the network cmdlets in action.<\/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 an email to The Scripting Guys 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 remember eat your cmdlets each and every day with a taste dash of creativity.<\/p>\n<p><b>Sean Kearney, <\/b>Windows PowerShell MVP, Honorary Scripting Guy&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Discover Windows PowerShell cmdlets and modules in Windows Server&nbsp;2012&nbsp;R2 for networking. &nbsp;Hey, Scripting Guy! I used to use netsh.exe&nbsp;to try to automate my server configurations. I can deal with it, but I heard that you can do a lot of this with Windows PowerShell in Windows Server&nbsp;2012&nbsp;R2. Do you know how I figure out [&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,37,154,45],"class_list":["post-1653","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-networking","tag-sean-kearney","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Discover Windows PowerShell cmdlets and modules in Windows Server&nbsp;2012&nbsp;R2 for networking. &nbsp;Hey, Scripting Guy! I used to use netsh.exe&nbsp;to try to automate my server configurations. I can deal with it, but I heard that you can do a lot of this with Windows PowerShell in Windows Server&nbsp;2012&nbsp;R2. Do you know how I figure out [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1653","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=1653"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1653\/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=1653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=1653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=1653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}