IP Address using PowerShell

Setting up the Network IP address using PowerShell is one of the easiest methods. For any computer to communicate each system should have its own address and this can be achieved by IP Address.

Below are the steps I will help you understand the basics if how to setup he Network TCP/IP using PowerShell. This can also be used as a prerequisite for setting up Active Directory.

Just 4 steps are involved to setup the whole network using PowerShell

  1. Find and identify the network adapter on which you want to set IP (Get-NetIPInterface)
  2. Give new IP Address (New-NetIPAddress)
  3. Set DNS Server Address (Set-DNSClientServerAddress)
  4. Set Default Gateway for internet routing (New-NetRoute)

Run PowerShell as Administrator

1. Find and identify the network adapter on which you want to set IP:

For this we need to use ‘Get-NetIPAddress’ cmdlet as below. You will find all the network adapter present on your computer with details such as type of card (Ethernet or Wi-Fi), IP Version (IPv4 or IPv6) etc

Get-NetIPInterface
PowerShell

2. View the current assigned IP Address:

To view the current IP Address assigned use below cmdlet.

Get-NetIPAddress -AddressFamily IPv4  -InterfaceAlias Ethernet
PowerShell

3. Now set the IP address to the card.

Here I am using Ethernet card so I will assign the IP to Ethernet with IPv4 address family

New-NetIPAddress
–InterfaceAlias Ethernet
–AddressFamily IPv4
–IPAddress 192.168.10.12
–PrefixLength 24
PowerShell

4. Set DNS Server Address

Now set the DNS server IP address by using ‘Set-DNSClientServerAddress’ cmdlet I have assigned both DNS server IP address.

Set-DnsClientServerAddress
–InterfaceAlias Ethernet
–ServerAddress “192.168.10.12”, “192.168.10.11”

5. Set the Default Gateway

In the last step set the Default Gateway which is your router IP for routing Internet For assigning default gateway you need to use New-NetRoute cmdlet with DestinationPrefix and NextHop parameters along with the InterfaceAlias.

New-NetRoute –DestinationPrefix 0.0.0.0/0 –NextHop “192.168.10.1” –InterfaceAlias Ethernet
PowerShell

Final output would be as below

PowerShell

Leave a Reply

Your email address will not be published.