Disabling IPv6 via Chef on Windows

While there are lots of resources on the Internet for disabling IPv6 on Linux, there are very few that show how to disable IPv6 on Windows.  Here is a quick recipe that I put together that will disable IPv6 and restart if needed.

powershell_script "disable_ipv6" do
    guard_interpreter :powershell_script
    code "New-ItemProperty 'HKLM:\\SYSTEM\\CurrentControlSet\\services\\TCPIP6\\Parameters\\' -Name 'DisabledComponents' -Value '0xffffffff' -PropertyType 'DWord'"
    notifies :reboot_now, 'reboot[disable_ipv6_requires_reboot]', :immediately
    not_if "(Get-ItemProperty -Path 'HKLM:\\SYSTEM\\CurrentControlSet\\services\\TCPIP6\\Parameters' -Name DisabledComponents -ErrorAction SilentlyContinue).DisabledComponents -ne $null"
end

reboot 'disable_ipv6_requires_reboot' do
    action :nothing
    reason 'Disabling IPv6 requires a reboot to take effect.'
end

Before you use this, you should know that Microsoft do not recommend you disable IPv6.  You will experience a 5 second delay during the boot up process and Microsoft does not explicitly test this scenario.

Another interesting thing about this recipe is the condition used in the not_if.  I initially wanted to use Test-Path, but it turns out that Test-Path doesn’t work on registry values, it only works on registry paths.   I got around this using Get-ItemProperty and testing for a null value.

Facebooktwittergoogle_plusredditmail

Leave a Reply