views:

75

answers:

1

Hi,

I have been trying to create a post login script that will change the default gateway to a specific IP and then renews its IP but haven't had any luck. I know the normal cmd line is ipconfig \renew for renewing it IP. Any help would be appreciated.

Thanks

A: 

EDIT: I edited the old answer out as the changing dhcp to default gateway essentially makes it a new question.

Since you tagged powershell, the powershell way to do this is basically change this using WMI.

We can create the following function to do this:

function Set-IPAddress {
  param(  [string]$networkinterface,
  [string]$gateway
  )

  $index = (gwmi Win32_NetworkAdapter | where {$_.netconnectionid -eq $networkinterface}).InterfaceIndex
  $NetInterface = Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.InterfaceIndex -eq $index}
  $NetInterface.SetGateways($gateway)
}

*I haven't explicitly tested this function.

Basically what we do, is get the number of our network adapter (index) based on it's name (networkinterface). Then we get the AdapterConfiguration object associated with that interface, and then Set the Gateway to the new gateway, which is the second function parameter.

The other way to do it in batch would be to call the netsh program. I think what you're looking for is along these lines.

netsh interface ip delete address "local area connection" gateway=all
netsh interface ip add address "local area connection" gateway=100.1.1.5 gwmetric=2

* Again, I haven't tested this.

Kevin Nisbet
sorry, i mistyped and changed it. Looking for a script that changes the default gateway not the DHCP Server.Thanks
Bruce227