This script elevates to Administrator if needed and then toggles IPv6 support on the adaptor specified depending on what it currently is
# Self-elevate the script if required
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
$adapter = "Ethernet 2"
$enabled = (Get-NetAdapterBinding -ComponentID ms_tcpip6 -Name $adapter).Enabled
if ($enabled) {
Write-Host "Disabling IPv6 on Ethernet 2"
Disable-NetAdapterBinding -Name $adapter -ComponentID ms_tcpip6
}
else {
Write-Host "Enabling IPv6 on Ethernet 2"
Enable-NetAdapterBinding -Name $adapter -ComponentID ms_tcpip6
}
#output the current state of IPv6 Support
Get-NetAdapterBinding -ComponentID ms_tcpip6 -Name $adapter
# output the current IP Addresses
Get-NetIPAddress -InterfaceAlias Ethernet | Select IPAddress
$sleep = 5
Write-Host "`n`n"
Write-Host Sleeping $sleep
Start-Sleep -Seconds $sleep
Check you have an IPv6 address or not with:
Get-NetIPAddress -InterfaceAlias Ethernet | Select IPAddress
Output
IPAddress
---------
fe80::5d5d:9fdd:f6e2:2066%23
2407:3200:31e:2ae0:fbbe:f8ef:7ec3:75e1
2407:3200:31e:2ae0:e857:e8ef:de58:7948
10.19.14.19
0 Comments