Configure networking with Powershell

    Since Windows Server 2012 some interesting commands have been added that allow us to configure elements related to networking with Powershell. There are a couple of modules with which we can manage network adapters from the hardware level, set or reset things like IP addresses or DNS servers, receive information in a detailed view and more.

    In this post I will cover some very basic tasks that for sure you need to perform somewhat often. Why not try them from Powershell and forget the GUI? For the example I am using Windows Server 2016.

    Managing network adapters

    Let’s look at what info we can gather about the NICs attached to our system. In this case I am not talking about the logical settings like addresses or DNS servers, but the hardware part like status, offloading and more. The CmdLets we will use for this part are found in the NetAdapter Powershell module. Here is how to list all of them:

Networking with Powershell: List netadapter commands

Networking with Powershell: List netadapter commands

    You will get a big list. Don’t be scared. Let’s first find out some basic info about our NICs.

Networking with Powershell: Get adapter info

Networking with Powershell: Get adapter info


Get-NetAdapter

    We just got some very basic info like the adapter name and index which we can use when referencing it, the MAC address and the Connection Status. You can see that in my case it is Disconnected because the NIC is not placed in a Hyper-V switch. When you need to see more info just run the following command to get all of the adapter’s properties:


Get-NetAdapter | fl *

    Another thing we can obtain which might be useful is the list of bindings for a network adapter. The bindings are all the components like IPv4, IPv6, QoS etc. Use the following command to do this:

Networking with Powershell: Get NIC bindings

Networking with Powershell: Get NIC bindings


Get-NetAdapterBinding -Name Ethernet

   When you work with network adapters you for sure need to Disable one, or Enable it or maybe just Reset it. We can perform these 3 tasks from Powershell with 3 simple commands. For a disable/enable cycle just run:

Restrt a NIC

Restart a NIC

    The other 2 tasks are just as simple. When you disable a NIC you can use -Confirm:$false so Powershell will not ask you to validate the action.

Networking with Powershell: Disable and Enable NIC

Networking with Powershell: Disable and Enable NIC

   I will not talk about the rest of the commands from this module. In case you need to enable or disable any offloading features or other hardware related settings, check the help online. 

    Making logical configurations to NICs

    We are done with the hardware part. Now I want to have a look at tasks like setting IPs, configuring DNS servers and more. We will use 2 modules to configure and view these settings because DNS specific things are separated. To get a list of commands for the 2 modules just run:


Get-Command -Module NetTCPIP

Get-Command -Module DnsClient

   Let’s start running commands. First I want to get IP address info about my network adapter with index 2. By running the CmdLet with only the -Index parameter we will receive IPv4 and IPv6 information.

Networking with Powershell: Get IP info

Networking with Powershell: Get IP info

    The address was obtained from a DHCP server as can be seen. In case you want to set a static address you have to use the New-NetIPAddress CmdLet:

Set an IP address

Set an IP address


New-NetIPAddress -IPAddress 192.168.1.6 -DefaultGateway 192.168.1.254 -AddressFamily IPv4 -PrefixLength 24 -InterfaceIndex 2

    In order to finish the configuration we should also add at least a DNS server. If you look right now at the DNS settings for the NIC you will see there is no server present; just the IPv6 autoconfigured ones.

Networking with Powershell: Get DNS serves

Networking with Powershell: Get DNS serves

    Here is how to set 2 DNS servers on the NIC:

Set DNS servers

Set DNS servers

    In case you have problems with this command because of the autoconfigured IPv6 servers just run this CmdLet:


Set-DnsClientServerAddress -InterfaceIndex 2 -ResetServerAddresses

    At one point you may need to set a specific interface on DHCP. You can do this easily also. Like or the static address, when setting a NIC on DHCP we have to reset the static DNS servers. First set the address to DHCP.

Set NIC on DHCP

Set NIC on DHCP

    Once we ran this command 3 things happened:

  • We managed to set the address,mask and gateway on DHCP
  • We left the DNS settings intact
  • The system did not query a DHCP server for an address

    I did not manage to find a way to make the system query a DHCP server using a Powershell command. For this task let’s rely on the trusty ipconfig /renew trick.

Networking with Powershell: renew address

Networking with Powershell: renew address

    In order to make the DNS server part of the IP settings take info from DHCP also just remove the servers configured previously.


Set-DnsClientServerAddress -InterfaceIndex 2 -ServerAddresses ""

    Now the interface is on DHCP. One last command I want to show you is used to give you an ipconfig type look at the IP settings. Here it is:

View IP settings

View IP settings

    In this post I showed you just a few simple and useful commands to configure networking on a Windows machine.

Leave a Comment

Your email address will not be published. Required fields are marked *