开发者

Post login script pointing to new dhcp server

I hav开发者_运维问答e 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜