Managing Network Settings with PowerShell 7

Built-in PowerShell 7 module NetTCPIP, on Windows, offers a range of functionality to update and manage your network interfaces. Many of the traditional IT administration tasks, such as setting a static IP address or DNS Server settings, are trivial using the functions within the NetTCPIP module.

Let’s explore a typical series of steps that many an IT administrator might face. Setting up a new server and it’s associated network interface.

Discovering Network Interfaces

Perhaps you’ve been tasked with setting up a brand new virtual machine (VM) and configuring its network interface. Rather than go through the GUI, you know PowerShell is already installed on the latest version and ready to go. After opening up a new console session, the first thing we need to do is see what our network interfaces currently are.

The cmdlet, Get-NetAdapter, will display every network interface that the system is aware of. From there we can further filter the results to just get to what we want to modify.

In this particular server, we have two network interfaces to worry about. To make sure that we are only working on the one we want, let’s make sure to just get our Ethernet 1 interface and save it to a variable, $Adapter for later use.

Disabling Unnecessary Network Interfaces

Earlier we mentioned that there were two network interfaces on this system. Well, we don’t need to use the second one. Though it may be used in the future, it’s best to avoid confusion, so let’s disable the interface. After that, let’s verify that it really is disabled.

Configuring a Static IP Address

Now that we have the network interface we want, we need to assign the IP addressing information that we were given. Our network team gave us the following IP details to assign.

  • IP Address:
  • Subnet:
  • Gateway:
  • Prefix Length: 24

Given the above details, we can assign these values to our network interface using the New-NetIPAddress cmdlet. Using the previously stored adapter in our $Adapter variable, we can quickly update the network interface configuration.

Before we move on though, we need to make sure that the configuration took correctly. Using our same $Adapter variable we can pull back just the information we want from our interface.

Renaming a Network Adapter

If you have multiple network adapters on a system, it can be very useful to name them according to their function. In this case, we want to rename our first adapter to that of Internal Network. This will help distinguish it from our secondary adapter when we do bring that only eventually. Thankfully, there is a handy Rename-NetAdapter function that we can use. It doesn’t take the InterfaceIndex unfortunately and you must use the name of the interface.

Setting Custom DNS Servers

Though we have set up our new interface, something isn’t quite right about our DNS Servers, notably that we have none! In this case, we need to set those manually, to the following that have been provided by our networking team.

  • DNS Server 1:
  • DNS Server 2:

Using the Set-DNSClientServerAddress we can define our DNS Server addresses to be used on the given interface. You may notice the use of the [IPAddress] accelerator, this will validate the IP Address and throw an error in case we mistyped or used a wrong one.

After we run Get-NetIPConfiguration one more time, we can see that our DNS addresses are now set! As you can see below the InterfaceAlias property is showing our new name that we previously set as well.

Managing Network Interfaces Using PowerShell 7

Though this is just the beginning, if you were to take this one step further you could script these tasks to apply to multiple servers. If you have been given the task to provision a large number of computers, by utilizing these cmdlets, you would be able to make short work of that task. This can save countless hours stuck in GUI’s and ultimately make you, the administrator, far more productive.

As you can tell, it’s trivial to manage our Network Interface within PowerShell 7. An IT administrator can make quick work of automating the configuration and setup using the many available cmdlets to do so!

Related Topics:

  • PowerShell

    Don't have a login but want to join the conversation? Sign up for a Petri Account

    Entrepreneur, hustler, husband, dad, Automator, content producer, published author, Microsoft MVP, DevOps pro and passionate problem-solver.