Skip to content

Instantly share code, notes, and snippets.

@nazq
Created November 19, 2023 01:09
Show Gist options
  • Select an option

  • Save nazq/65d81ac4c6feaf81a8b85a40e918a549 to your computer and use it in GitHub Desktop.

Select an option

Save nazq/65d81ac4c6feaf81a8b85a40e918a549 to your computer and use it in GitHub Desktop.
Powershell Script to disable IPV6
# Check if the script is running with administrator privileges
$principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
# Relaunch the script with elevated permissions
Start-Process -FilePath "powershell" -ArgumentList "-File $($MyInvocation.MyCommand.Path)" -Verb RunAs
exit
}
# Get network adapters and their IPv6 status
$adapters = Get-NetAdapterBinding | Select-Object Name, DisplayName, ComponentID, Enabled
# Display status before disabling IPv6
Write-Host "Before disabling IPv6 where enabled:" -ForegroundColor Magenta
$adapters | ForEach-Object {
if ($_.ComponentID -match 'ms_tcpip6' -and $_.Enabled -match 'False') {
Write-Host "$($_.Name) ==> IPv6 Disabled" -ForegroundColor Yellow
}
if ($_.ComponentID -match 'ms_tcpip6' -and $_.Enabled -match 'True') {
Write-Host "$($_.Name) ==> IPv6 Enabled" -ForegroundColor Green
Disable-NetAdapterBinding -Name $_.Name -ComponentID 'ms_tcpip6'
}
}
# Display status after disabling IPv6
Write-Host "" # Add a blank line for readability
Write-Host "After disabling IPv6 where enabled:" -ForegroundColor Magenta
$adapters | ForEach-Object {
if ($_.ComponentID -match 'ms_tcpip6' -and $_.Enabled -match 'False') {
Write-Host "$($_.Name) ==> IPv6 Disabled" -ForegroundColor Yellow
}
if ($_.ComponentID -match 'ms_tcpip6' -and $_.Enabled -match 'True') {
Write-Host "$($_.Name) ==> IPv6 Enabled" -ForegroundColor Green
}
}
# Display a message to prompt the user to press any key
Write-Host "Press any key to exit..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment