Enabling DHCP via PowerShell results in 2 WiFi connections to same network

خرید بک لینک

I have a VM on my network setup as a gateway that I use sometimes, while most of the time I just leave my PCs configured to use DHCP and just have everything go through the router. I had been swapping back and forth manual through the connection properties form but I've decided to try and make PowerShell scripts to simplify the process.

I also disable IPv6 when routing through the VM, but reenable it when I use DHCP. To switch to using the VM as a Gateway I use this:

# Get the adapter to change
$wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled ='true'";

# Get current IPv4 address of host
$ip = $wmi.IpAddress[0];

# Configure adapter to use 192.168.1.135 as the default gateway
$wmi.EnableStatic($ip, "255.255.255.0");
$wmi.SetGateways("192.168.1.135", 1);
$wmi.SetDNSServerSearchOrder("192.168.1.135");

# Disable IPv6
Get-NetAdapterBinding | Where-Object {$_.ComponentID.Equals("ms_tcpip6")} | ForEach-Object {
    Disable-NetAdapterBinding -InterfaceAlias $_.Name -ComponentID ms_tcpip6
}

And this works exactly as it does when I configure it manually. My normal network connection changes to "NetworkName 2" in the Network and Sharing Center. To switch back to DHCP, I run this script:

# Get the adapter to change
$wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled ='true'";

# Configure adapter to use DHCP and automatic DNS
$wmi.EnableDHCP();
$wmi.SetDNSServerSearchOrder();

# Enable IPv6
Get-NetAdapterBinding | Where-Object {$_.ComponentID.Equals("ms_tcpip6")} | ForEach-Object {
    Enable-NetAdapterBinding -InterfaceAlias $_.Name -ComponentID ms_tcpip6
}

And afterwards, I have two connections through WiFi to my network, a Private network called "NetworkName" and a Public network called "NetworkName 3." IPv6 and DHCP are enabled on both.

What is it with my DHCP script that causes this? It didn't happen when I switched back to DHCP through the dialog.

Recent Questions...

ما را در سایت Recent Questions دنبال می‌کنید

برچسب: نویسنده: استخدام کار بازدید: 278 تاريخ: سه شنبه 29 تير 1395 ساعت: 9:13

صفحه بندی