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.
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 0.0.0.0/0
To set the ip-address for the network adapter, use the New-NetIPAddress cmdlet. For example, add ip-address 192.168.20.10 with subnetmask 255.255.255.0 (prefixlength 24) and default gateway 192.168.20.254.
New-NetIPAddress -InterfaceIndex 4 -IPAddress 192.168.20.10 -PrefixLength 24 -DefaultGateway 192.168.20.254
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 192.168.20.10
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.
A reboot is required!