{"id":1628,"date":"2014-04-11T00:01:00","date_gmt":"2014-04-11T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/04\/11\/windows-server-2012-r2-network-cmdlets-part-5\/"},"modified":"2014-04-11T00:01:00","modified_gmt":"2014-04-11T00:01:00","slug":"windows-server-2012-r2-network-cmdlets-part-5","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/windows-server-2012-r2-network-cmdlets-part-5\/","title":{"rendered":"Windows Server 2012 R2 Network Cmdlets: Part 5"},"content":{"rendered":"<p><b>Summary<\/b>: Use Windows PowerShell to work with IP addresses and DNS.<\/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!<\/p>\n<p>How can I add the DNS settings to the network adapter in Windows Server&nbsp;2012&nbsp;R2? I&rsquo;m a little lost on this one.<\/p>\n<p>&mdash;RJ<\/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 RJ,<\/p>\n<p>Honorary Scripting Guy, Sean Kearney, is here today to pour out some more PowerShell love. This is the fifth part in a series called Windows PowerShell Network Week. You also might enjoy reading:<\/p>\n<ul>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/windows-server-2012-r2-network-cmdlets-part-1\/\" target=\"_blank\">Windows Server 2012 R2 Network Cmdlets: Part&nbsp;1<\/a><\/li>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/windows-server-2012-r2-network-cmdlets-part-2\/\" target=\"_blank\">Windows Server 2012 R2 Network Cmdlets: Part&nbsp;2<\/a><\/li>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/windows-server-2012-r2-network-cmdlets-part-3\/\" target=\"_blank\">Windows Server 2012 R2 Network Cmdlets: Part&nbsp;3<\/a><\/li>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/windows-server-2012-r2-network-cmdlets-part-4\/\" target=\"_blank\">Windows Server 2012 R2 Network Cmdlets: Part&nbsp;4<\/a><\/li>\n<\/ul>\n<p>I keep thinking of that line from Star Wars, &ldquo;&hellip;and now the circle is complete.&rdquo; Well, at least mostly for setting up a basic network configuration. We have learned how to identify and work with our network adapters, setup IP addresses, and control the firewall ports. We&rsquo;ve even seen how we can easily disable power management on the adapters or give them a new name.<\/p>\n<p>But without DNS resolution, we might find that trying to hit our local WSUS server or pulling in our antivirus updates is a bit troublesome. That is unless you want to manually edit all of your host files in your environm&hellip;<\/p>\n<p>*THWAP!*<\/p>\n<p>Hey, who threw that?<\/p>\n<p>OK. Editing the host files across an entire enterprise would be a bad idea. That is why we have our DNS servers to keep the name resolution centralized.<\/p>\n<p>Fortunately, this is also easy in Windows PowerShell. There are a series of <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/jj590772.aspx\" target=\"_blank\">DNS Client cmdlets<\/a> to perform all of this magic for us.<\/p>\n<p>The new friend we&rsquo;re going to be dealing with is the <b>Get-DnsClientServerAddress<\/b> cmdlet. We can specify a network adapter in its settings to obtain the IP addresses that are in use for DNS.<\/p>\n<p style=\"margin-left:30px\">Get-DnsClientServerAddress &ndash;InterfaceAlias &ldquo;Local Area Connection&rdquo;<\/p>\n<p>Or we can make our lives easier and ask for only the live network adapters:<\/p>\n<p style=\"margin-left:30px\">Get-NetAdapter &ndash;physical | where { $_.Status &ndash;eq &lsquo;Up&rsquo; } | Get-DnsClientServerAddress<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8032.1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8032.1.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>By using the <b>Set-DnsClientServerAddress<\/b> cmdlet, we can assign DNS configuration to cards that have a static IP address like this:<\/p>\n<p style=\"margin-left:30px\">Set-DnsClientServerAddress &ndash;InterfaceAlias &ldquo;Local Area Connection&rdquo; &ndash;ServerAddresses (&ldquo;192.168.1.5&rdquo;)<\/p>\n<p>You can even assign a DNS extension to the network adapter. This is done by using the <b>Set-DnsClient<\/b> cmdlet:<\/p>\n<p style=\"margin-left:30px\">Set-DnsClient &ndash;InterfaceAlias &ldquo;Local Area Connection&rdquo; &ndash;ConnectionSpecificSuffix &ldquo;Fabrikam.com&rdquo;<\/p>\n<p>If you like, you can even pipe a list of adapters with <b>Get-Adapter<\/b> and assign it &ldquo;en-masse:&rdquo;<\/p>\n<p style=\"margin-left:30px\">Get-NetAdapter &ndash;physical | Set-DnsClientServerAddress &ndash;ServerAddresses (&ldquo;192.168.1.5&rdquo;)<\/p>\n<p>But the DNSClient module has powers built in to make your life easier outside of mere network adapter configuration. It has what I think is the coolest cmdlet to date! The <b>Resolve-DNSName<\/b> cmdlet.<\/p>\n<p>It seems such a simple idea, but this isn&rsquo;t the same as what <b>Test-Connection<\/b> does, which is (at most) a name to IP resolution. No, this is the entire power of the old NSlookup console command in one cmdlet!<\/p>\n<p>Something that I used to want to know in my environment was, &ldquo;Who has the following IP address?&rdquo; If I was lucky, I could flip the IP to the name with an NBTSTAT command like this:<\/p>\n<p style=\"margin-left:30px\">NBTSTAT &ndash;a<\/p>\n<p>That was one of the older methods to obtain the name of a computer given its IP address. But unless you entered into Nslookup, I don&rsquo;t remember any easy way to do that with a DNS server from the client side. But now there is:<\/p>\n<p style=\"margin-left:30px\">Resolve-DNSName 192.168.1.145<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6507.2.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6507.2.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>I saw that, and my eyes lit up! &ldquo;That&rsquo;s COOL!&rdquo;<\/p>\n<p>Let&rsquo;s try some basic stuff that you can now access directly from Windows PowerShell for DNS&hellip;show me the MX servers for a particular domain!<\/p>\n<p style=\"margin-left:30px\">Resolve-DNSName &ndash;type MX PowerShell.ca<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1856.3.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1856.3.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>All of this kind of Power is built in to the Windows Server&nbsp;2012&nbsp;R2 console. Ready for you.<\/p>\n<p>Hey look, RJ! The weekend is coming up, and believe it or not, we&rsquo;ve got some more Windows PowerShell coolness coming around the corner tomorrow with WebDAV. Be sure to check it out!<\/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: Use Windows PowerShell to work with IP addresses and DNS. &nbsp;Hey, Scripting Guy! How can I add the DNS settings to the network adapter in Windows Server&nbsp;2012&nbsp;R2? I&rsquo;m a little lost on this one. &mdash;RJ &nbsp;Hello RJ, Honorary Scripting Guy, Sean Kearney, is here today to pour out some more PowerShell love. This is [&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-1628","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: Use Windows PowerShell to work with IP addresses and DNS. &nbsp;Hey, Scripting Guy! How can I add the DNS settings to the network adapter in Windows Server&nbsp;2012&nbsp;R2? I&rsquo;m a little lost on this one. &mdash;RJ &nbsp;Hello RJ, Honorary Scripting Guy, Sean Kearney, is here today to pour out some more PowerShell love. This is [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1628","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=1628"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1628\/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=1628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=1628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=1628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}