Network and Hostname Configuration using Powershell

This tutorial shows how to configure your network adapter and change the hostname using Powershell. For this tutorial a Windows Server 2016 Standard Edition server has been used without Desktop Experience.

Log in as Administrator. A Command Shell is shown. Type ‘powershell’ and hit enter.

Network Configuration

First you need to know which network adapters are available by using the Get-NetAdapter cmdlet. This will show all network adapter names, the interface index and the status for each network adapter.


Get-NetAdapter | ft Name,ifIndex,Status

Remember the ifIndex (InterfaceIndex) value for the network adapter that you want to configure.


If DHCP is already available on the network, the network adapter may already have an ip-address. To show the ipv4 ip-address for a specific network adapter, use the Get-NetIPAddress cmdlet. (You may use a different interface index value.)


Get-NetIPAddress -InterfaceIndex 4 -AddressFamily ipv4


To check all routes, including the default gateway, use the Get-NetRoute cmdlet.

Get-NetRoute -InterfaceIndex 4

To check the default gateway only:

Get-NetRoute -InterfaceIndex 4 -DestinationPrefix


To set the ip-address for the network adapter, use the New-NetIPAddress cmdlet. For example, add ip-address with subnetmask (prefixlength 24) and default gateway


New-NetIPAddress -InterfaceIndex 4 -IPAddress -PrefixLength 24 -DefaultGateway

To verify that the ip-address has been added correctly, use the Get-NetIPAddress cmdlet again.


To set the DNS ip-addresses, use the Set-DNSClientServerAddress cmdlet. Use a comma to separate multiple DNS ip-addresses.


Set-DNSClientServerAddress -InterfaceIndex 4 -ServerAddresses


Hostname Configuration

To check the current hostname, use the ‘env’ variable.



To change the current hostname, use the Rename-Computer cmdlet. For example, change the computername to ADDS01.


Rename-Computer ADDS01

A reboot is required!

2 thoughts on “Network and Hostname Configuration using Powershell

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.