Discussion:
Adding IP's to 'Advanced TCP/IP Settings'
(too old to reply)
Mehdis
2009-12-22 10:58:02 UTC
Permalink
Hi all,

I want to write a script in powershell that will add IP's to a nic. i.e.
when added they will appear on the IP Addresses section on 'Advanced TCP/IP
Settings' of the TCP/IPv4 properties in 'Local Area Connection Properties'.

I've been looking at Win32_NetworkAdapterConfiguration however all the
examples I have seen so far just talk about getting IP addresses and adding a
static IP.

Another consideration.....is there any best practices for adding hundreds of
IP's all in one go? Will doing them all in one go give any kind of
performance hit?

Hope someone can help me with this as I'm a little stumped.
Much appreciated.
Darko Bazulj
2009-12-22 12:18:19 UTC
Permalink
Post by Mehdis
Hi all,
I want to write a script in powershell that will add IP's to a nic. i.e.
when added they will appear on the IP Addresses section on 'Advanced TCP/IP
Settings' of the TCP/IPv4 properties in 'Local Area Connection
Properties'.
I've been looking at Win32_NetworkAdapterConfiguration however all the
examples I have seen so far just talk about getting IP addresses and adding a
static IP.
Another consideration.....is there any best practices for adding hundreds of
IP's all in one go? Will doing them all in one go give any kind of
performance hit?
Hope someone can help me with this as I'm a little stumped.
Much appreciated.
--
Hi,

try with

netsh interface ipv4 add address "Local Area Connection" 10.0.0.2 255.0.0.0

Regards,
Darko Bazulj
Joe Morris
2009-12-22 15:05:38 UTC
Permalink
Post by Darko Bazulj
Post by Mehdis
I want to write a script in powershell that will add IP's to a nic. i.e.
when added they will appear on the IP Addresses section on 'Advanced
TCP/IP Settings' of the TCP/IPv4 properties in 'Local Area
Connection Properties'.
I've been looking at Win32_NetworkAdapterConfiguration however all the
examples I have seen so far just talk about getting IP addresses and
adding a static IP.
Another consideration.....is there any best practices for adding hundreds
of IP's all in one go? Will doing them all in one go give any kind of
performance hit?
netsh interface ipv4 add address "Local Area Connection" 10.0.0.2
255.0.0.0
...and to see what it takes to specify the various settings associated with
a NIC, manually configure it on any machine, then from a command prompt
issue the command:

NETSH INTERFACE DUMP > FOO.TXT

Make any changes required, then from a remote script (presumably POSH)
invoke NETSH again>

NETSH < FOO.TXT

and sit on your hands until the command terminates, which may be several
seconds. This assumes, of course, that the NIC has the same name in all
systems; if not you'll have to customize the IP configuration commands.

Here's an example of the FOO.TXT file from one of my XP systems (minus the
IPv6 components and most of the blank lines):

====== start included text ======

#========================
# Interface configuration
#========================
pushd interface
reset all
popd
# End of interface configuration

#========================
# Port Proxy configuration
#========================
pushd interface portproxy
reset
popd
# End of Port Proxy configuration

# ----------------------------------
# Interface IP Configuration
# ----------------------------------
pushd interface ip
# Interface IP Configuration for "Local Area Connection"
set address name="Local Area Connection" source=static addr=192.168.0.130
mask=255.255.255.0
set address name="Local Area Connection" gateway=192.168.0.254 gwmetric=0
set dns name="Local Area Connection" source=static addr=192.168.0.106
register=PRIMARY
add dns name="Local Area Connection" addr=192.168.0.254 index=2
set wins name="Local Area Connection" source=static addr=192.168.0.106
popd
# End of interface IP configuration

====== end included text ======

I've been using this technique (manual, not scripted) for years to
reconfigure systems when moving between test and production networks.

Joe Morris
Mehdis
2009-12-29 10:53:01 UTC
Permalink
Thanks Joe for your elegant and thourough solution and thanks Darko for
pointing me in the right direction. What I did is below. Hope it helps anyone
else out there. Not elegant, but it got it done.

Thanks again.

========================================================
#This script will add a range of IP's to the Local Area Connection interface
$prefix=Read-Host "Enter IP prefixes (end with a '.')"
Write-Host "!ENSURE THE RANGES YOU GIVE ARE WITHIN LIMITS!" -foregroundcolor
red
$startip = Read-Host "Enter START IP value"
$endip = Read-Host "Enter END IP value"
$subnet= Read-Host "Enter Subnet Mask"

$nicname="Local Area Connection" #change with what ever name of NIC is

[int]$ips=$startip
[int]$ipe=$endip

for($i=$ips;$i -le $ipe;$i++)
{
$addr = $prefix + $i.ToString()
Write-Host "Adding IP... " $addr
netsh interface ipv4 add address $nicname $addr $subnet
Write-Host "OK!" -foregroundcolor green
}
Write-Host "Completed."

======================================================
Post by Darko Bazulj
Post by Mehdis
I want to write a script in powershell that will add IP's to a nic. i.e.
when added they will appear on the IP Addresses section on 'Advanced
TCP/IP Settings' of the TCP/IPv4 properties in 'Local Area
Connection Properties'.
I've been looking at Win32_NetworkAdapterConfiguration however all the
examples I have seen so far just talk about getting IP addresses and
adding a static IP.
Another consideration.....is there any best practices for adding hundreds
of IP's all in one go? Will doing them all in one go give any kind of
performance hit?
netsh interface ipv4 add address "Local Area Connection" 10.0.0.2
255.0.0.0
....and to see what it takes to specify the various settings associated with
a NIC, manually configure it on any machine, then from a command prompt
NETSH INTERFACE DUMP > FOO.TXT
Make any changes required, then from a remote script (presumably POSH)
invoke NETSH again>
NETSH < FOO.TXT
and sit on your hands until the command terminates, which may be several
seconds. This assumes, of course, that the NIC has the same name in all
systems; if not you'll have to customize the IP configuration commands.
Here's an example of the FOO.TXT file from one of my XP systems (minus the
====== start included text ======
#========================
# Interface configuration
#========================
pushd interface
reset all
popd
# End of interface configuration
#========================
# Port Proxy configuration
#========================
pushd interface portproxy
reset
popd
# End of Port Proxy configuration
# ----------------------------------
# Interface IP Configuration
# ----------------------------------
pushd interface ip
# Interface IP Configuration for "Local Area Connection"
set address name="Local Area Connection" source=static addr=192.168.0.130
mask=255.255.255.0
set address name="Local Area Connection" gateway=192.168.0.254 gwmetric=0
set dns name="Local Area Connection" source=static addr=192.168.0.106
register=PRIMARY
add dns name="Local Area Connection" addr=192.168.0.254 index=2
set wins name="Local Area Connection" source=static addr=192.168.0.106
popd
# End of interface IP configuration
====== end included text ======
I've been using this technique (manual, not scripted) for years to
reconfigure systems when moving between test and production networks.
Joe Morris
.
Continue reading on narkive:
Loading...