Question

I am writing a powershell script that will act as a build compliance test for our servers. One of the things I need to do is detect if IPv6 networking has been disabled.

WMI indicates that this information can be found in the IPAddress Property of Win32_NetworkAdapterConfiguration but can be both IPv6 or IPv4. This does not give me a "yes/no" answer I am hoping to find.

Other caveats are that I would prefer not to scrape the details by accessing the registry directly, nor scrape from the output of a command such as ipconfig.

Given our environment has a mix of 2003/2008 machines, can anyone think of a way to test for IPv6?

Cheers

Was it helpful?

Solution 3

Actually, a colleague came up with a nice way of doing it - a little clunky but works. :)

$IPV6 = $false
$arrInterfaces = (Get-WmiObject -class Win32_NetworkAdapterConfiguration -filter "ipenabled = TRUE").IPAddress

foreach ($i in $arrInterfaces) {$IPV6 = $IPV6 -or $i.contains(":")}

write-host $IPV6

OTHER TIPS

You can use the .NET way :

Write-Host 'OS Supports IPv6: ' $( [System.Net.Sockets.Socket]::OSSupportsIPv6 )

The property will be true if it is possible to create an IPv6 datagram socket. This property is also affected by the global machine.config file, so the IPv6 status may not always be accurate.

Edit: To test this on a remote machine, you can still use powershell, but it has to have powershell 2.0 installed, and WinRM enabled.

If those two conditions are true, then you can probably use Invoke-Command to do that.

Testing for IPv6 would usually be more complicated than a yes/no answer with XP you have,

  1. Is the "Microsoft TCP/IP version 6" network component installed.
  2. Is there an adapter has an IPv6 address - one would usually assume (1) implies (2).
  3. Whether an adapter has a global-scope IPv6, i.e. not just a link local fe80:: prefixed address or loopback interface, ::1.

Presumaly (1) can be found with a Powershell script as demonstrated by Microsoft:

http://gallery.technet.microsoft.com/ScriptCenter/en-us/c4eb1596-7ac9-4be7-a711-b43446a3e3df

If you want to specifically check that IPv6 is enabled and working, I'd say the best way would be to try and connect to a test host. That way, you won't just test some specific software setting, but you'll also find out so that all the routing configuration and everything around it works as it should.

This is what you didn't want to do, but it seems the best method, going over the output that netsh interface provides.

You may want to look here for what you're after. Your implementation would be simpler, but iterating over the netsh interface ipv6 show interfaces results is all you need, if you find interfaces, it's enabled somewhere, if you don't find any, it's not.

I've not tested this, but the .NET Socket class has a OSSupportsIPv6 property. So something along the lines

[System.Net.Sockets]::OSSupportsIPv6

The documentation says "true if the operating system and network adaptors support the IPv6 protocol; otherwise, false." It isn't clear to me if that means the value is based on what the OS is capable of, or what it is configured for.

I looked this up in my local help, so I don't have a MSDN link handy. Shouldn't be too hard to find.

I know this is an old thread but I needed to check the same thing.

To check ipv6 binding for a specific adapter use:

 Get-NetAdapterBinding -Name 'NameOfNic' -ComponentID ms_tcpip6

This will give you the enabled state for that adapter.

If you want to just retrieve that state you can use:

 (Get-NetAdapterBinding -Name 'NameOfNic' -ComponentID ms_tcpip6).Enabled

Hope this helps. I did check that this works as far back as 2012. docs.microsoft.com didn't list versions below default for 2012/Win8

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top