Automating IPv6 Disabling for Network Adapters with PowerShell

1 min. readlast update: 10.13.2024

IPv6 is an essential part of modern networking, but in certain environments, administrators may need to disable it for compatibility, security, or specific network requirements. Disabling IPv6 manually on multiple network interfaces can be time-consuming, so automating the process with PowerShell ensures consistency and efficiency.

This article walks through a PowerShell script that automates the process of detecting network adapters with IPv6 enabled and disables it where necessary.

Script Overview

This PowerShell script performs the following actions:

  1. Retrieves all network interfaces that are using IPv6.
  2. Checks if IPv6 is enabled on those interfaces.
  3. Disables IPv6 on interfaces where it is active.
  4. Logs the actions and provides a summary of how many interfaces had IPv6 disabled.

Here is the script:

$interfaces = Get-NetAdapter | Get-NetAdapterBinding | Where-Object ComponentID -EQ 'ms_tcpip6'
$disableCount = 0
foreach ($interface in $interfaces) {
  if ($interface.Enabled -eq $True) {
    Write-Output "Disabling IPV6 for $($interface.Name)"
    Disable-NetAdapterBinding -Name $interface.Name -ComponentID 'ms_tcpip6'
    $disableCount++
  } else {
    Write-Output "$($interface.Name) IPV6 is already disabled"
  }
}

if ($disableCount -eq 0) {
  Write-Output "No IPV6 interfaces were found to be disabled."
  exit 1
} else {
  Write-Output "$disableCount IPV6 interfaces were disabled."
  exit 0
}

Was this article helpful?