netsh

Cromewell

Administrator
Staff member
Hey guys, I've got a script written in netsh for windows 2008 r2.

Code:
pushd interface ipv4
reset
set global icmpredirects=enabled
add address name= "Local Area Connection" address= 192.168.1.100 mask=255.255.255.0
add route prefix=0.0.0.0/0 interface="Local Area Connection"  nexthop=192.168.1.1 metric=1  publish=Yes
set dns name= "Local Area Connection" static 192.168.1.1 192.168.1.2 primary
firewall set opmode disable
popd
I need to convert this to something that works on server 2003 r2. I was hoping it would be drop in compatible however, it seems things are different enough that it doesn't work. The TechNet documentation has been considerably less than useful on this.

What I've got so far isn't much, I've figured out that ipv4 should just be ip and that pretty much every other command errors out.
Code:
pushd interface ip
reset
set global icmpredirects=enabled
add address name= "Local Area Connection" address= 192.168.1.100 mask=255.255.255.0
add route prefix=0.0.0.0/0 interface="Local Area Connection"  nexthop=192.168.1.1 metric=1  publish=Yes
set dns name= "Local Area Connection" static 192.168.1.1 192.168.1.2 primary
firewall set opmode disable
popd
 

Cromewell

Administrator
Staff member
I never did figure out how to convert it, but I did rewrite a bit of it in powershell.
Code:
$dns = "192.168.1.2 192.168.1.3"
$searchOrder = $dns.split(" ")
$wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'"
$wmi.EnableStatic("192.168.1.200", "255.255.255.0")
$wmi.SetGateways("192.168.1.1", 1)
$wmi.SetDNSServerSearchOrder($searchOrder)
In case anyone is wondering, all the IPs and subnet masks and what-not are coming in through a context file from OpenNebula.
 
Top