<# -------------- Disable IPV6 -------------- AUTHOR: Yotam Krief MODIFIED BY: Bruno Ramos de Matos -------------- DESCRIPTION: This script disables IPV6, made for WSUS server as a prerequisite for JetPatch. NOTES: 1. Reboot at end of execution is mandantory in order for changes to take effect. 2. Reboot will be triggered automatically by the script, if all changes are successful. PREREQUISITE: - Powershell 4.0 - Run as administrator #> # DECLARED FUNCTIONS function ExitWithCode { param ( $exitcode ) $host.SetShouldExit($exitcode) } # SET VARIABLES $exitCode = 1 $exitcode_task1 = 1 $exitcode_task2 = 1 $ErrorActionPreference = "Inquire" $successActionCount = 0 $RegistryPath = 'HKLM:\SYSTEM\CurrentControlSet\services\TCPIP6\Parameters' $Name = 'DisabledComponents' $Value = '255' # CHECK AND DISABLE IPV6 ON ALL NETWORK ADAPTERS Get-NetAdapter | ForEach-Object { Disable-NetAdapterBinding -InterfaceAlias $_.Name -ComponentID ms_tcpip6 } $adaptersCount = 0 Get-NetAdapter | ForEach-Object { $ps=Get-NetAdapterBinding -InterfaceAlias $_.Name -ComponentID ms_tcpip6 Write-Host Name = $ps.Name Write-Host DisplayName = $ps.DisplayName Write-Host ComponentID = $ps.ComponentID Write-Host Enabled = $ps.Enabled Write-Host '' $adaptersCount++ if (!$ps.Enabled) { $successActionCount++ } } if ($successActionCount -eq $adaptersCount) { $exitcode_task1 = 0 } # CHECK AND DISABLE IPV6 SUPPORT ON SYSTEM VIA REGISTRY # Create the key if it does not exist If (-NOT (Test-Path $RegistryPath)) { New-Item -Path $RegistryPath -Force | Out-Null } # Now set the value Set-ItemProperty -Path $RegistryPath -Name $Name -Value $Value -Type DWORD -Force # Check if set value is correct $regproperty = Get-ItemProperty -Path $RegistryPath -Name $Name if ($regproperty.DisabledComponents -eq $Value ) { Write-Host "System support for IPv6 was disabled successfully!" Write-Host '' $exitcode_task2 = 0 } # CHECK IF BOTH TASKS WERE SUCCESSFUL. IF SO, THEN SET EXIT CODE TO 0 AND CALL FOR REBOOT if (($exitcode_task1 -eq 0) -And ($exitcode_task2 -eq 0)) { $exitcode = 0 write-Host "This computer is now going to reboot in order for changes to become fully effective..." Write-Host '' shutdown -r } ExitWithCode $exitCode exit $exitCode