Disable IPv6 on Windows 10 with PowerShell

Often when running a IPv4 only network it can be nice to not get rid of a lot of unneeded  info in the logs when it’s not in use.

If you are like me and like to have some control over what goes around your network, it is good to remove some of that noise that really doesn’t need to be there when checking logs and stuff.

I wrote a simple script that can enable/disable IPv6 on a specific network card or all network cards from Powershell, it uses standard commands, but wrapped up in a script.

On it’s own it can be quicker just to type the command by itself for a single network card but if you use it with other script or commands when you prep or config a new machine or reinstalling, it comes quite handy.

To find out specific network card names run the following command.

Get-NetAdapter

To run the script use it like this.

.\Set_IPv6_NetAdapterOptions.ps1 -AdapterName All -ipv6 Disable
.\Set_IPv6_NetAdapterOptions.ps1 -AdapterName All -ipv6 Enable
Or
.\Set_IPv6_NetAdapterOptions.ps1 -AdapterName <NetworkCardName> -ipv6 Enable
.\Set_IPv6_NetAdapterOptions.ps1 -AdapterName <NetworkCardName> -ipv6 Disable

Script in it’s full glory.

# Getting input parameters for script execution.
param (
    [Parameter(Mandatory=$true)][string]$AdapterName,
    [Parameter(Mandatory=$true)][string]$ipv6
)

# Enable IPv6.
if ($ipv6 -ieq "enable")
{
    if ($AdapterName -ieq "All") {
        # Get all adapter names
        $AdapterList = Get-NetAdapter | SELECT Name -ExpandProperty Name

        # Do the changes.
        foreach ($a in $AdapterList) {
            Enable-NetAdapterBinding -Name "$a" -ComponentID ms_tcpip6
        }
    }
    else {
        # Just change the one specified.
        Enable-NetAdapterBinding -Name "$AdapterName" -ComponentID ms_tcpip6
    }
}

# Disable IPv6.
if ($ipv6 -ieq "disable")
{
    if ($AdapterName -ieq "All") {
        # Get all adapter names
        $AdapterList = Get-NetAdapter | SELECT Name -ExpandProperty Name

        # Do the changes.
        foreach ($a in $AdapterList) {
            Disable-NetAdapterBinding -Name "$a" -ComponentID ms_tcpip6
        }
    }
    else {
        # Just change the one specified.
        Disable-NetAdapterBinding -Name "$AdapterName" -ComponentID ms_tcpip6
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *