Powershell – Set IPAddress

Yes, setting an IP Address is easy. Just go to Ethernet or LAN Adapter properties, select IPV4 Properties and change the IP Address to required. However all this will take around a minute to do so. Imagine if you have to do it multiple servers, it will take more time.

But if you do it via Powershell, it can be done easily and quickly on multiple servers.

Most of the time, I have been asked to perform following tasks:

  1. Disable IPV6
  2. Change IP Address details
    1. Change IP Address Interface to Static
    2. Set New IP Address
    3. Set DNS Server Addresses

All this can be done via following Powershell commands. But before we do we need to know the Interface Alias and Interface Index to set properties for right adapter.

  1. Get Interface Details
    1. Get-DNSClient

  2. Change DHCP mode to Disabled
    1. Set-NetIPInterface -InterfaceAlias “InterfaceName” -Dhcp Disabled

  3. Disable the TCP IPV6
    1. Disable-NetAdapterBinding -InterfaceIndex “IndexNo” -ComponentID “ms_tcpip6”

  4. Set New IP Address
    1. New-NetIPAddress -InterfaceIndex “IndexNo” -IPAddress xxx.xxx.xxx.xxx -PrefixLength 24 -DefaultGateway xxx.xxx.xxx.xxx

  5. Set New DNS Servers Addresses
    1. Set-DnsClientServerAddress -InterfaceIndex “IndexNo” -ServerAddresses “xxx.xxx.xxx.xxx , xxx.xxx.xxx.xxx”

Here is the Script to do so:


#Gets the Interafce Index and Alias
$IndexNo = (get-dnsclient | Where {$_.Interfacealias -match “ethernet”}).InterfaceIndex
$IndexAlias = (get-dnsclient | Where {$_.Interfacealias -match “ethernet”}).InterfaceAlias

#Set the New IP Address
$NewIPAddress =”″
$SubnetPrefixLength =”24″
$DefaultGateway =”″

#Set the DNS IP Addresses
$PrimaryDnsServer = “″
$SecondaryDnsServer = “″

Set-NetIPInterface -InterfaceAlias $IndexAlias -Dhcp Disabled

Disable-NetAdapterBinding -InterfaceAlias $IndexAlias -ComponentID “ms_tcpip6″

New-NetIPAddress -InterfaceIndex $IndexNo -IPAddress $NewIPAddress -PrefixLength $SubnetPrefixLength -DefaultGateway $DefaultGateway

Set-DnsClientServerAddress -InterfaceIndex $IndexNo -ServerAddresses “$PrimaryDnsServer , $SecondaryDnsServer “


That’s it. This is easy and effective way to configure you server.


Please give your feedback as they are important for me to improve on.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s