clear TCP/IP Gateway using WMI

来源:互联网 发布:怪物猎人x桐花套数据 编辑:程序博客网 时间:2024/05/17 01:35

solution 1:


To clear the gateway, set your gateway to the same IP you use on EnableStatic.



solution 2:


First we use WMI to grab the NIC by name ($NicName):


$Adapter = Get-WmiObject -Class Win32_NetworkAdapter-Filter "NetConnectionID='$NicName'"


Then we get the configuration for the NIC by calling it using the index number of the NIC we got from above:


$Nic = Get-WmiObject -ClassWin32_NetworkAdapterConfiguration -Filter"Index=$($Adapter.Index)"


Next, we need to grab the NIC’s IP and subnet mask so we can assign them again later:


$NicIP =$Nic.IpAddress[0]

$NicMask = $Nic.IpSubnet[0]


The, we set the NIC to DHCP,


$Nic.EnableDhcp() |Out-Null


And then back to static, using the IP and mask we retrieved from above:


$Nic.EnableStatic($NicIp,$NicMask) | Out-Null
0 0
原创粉丝点击