2

SetDNSServerSearchOrder returns 70, Information from the MSDN is "invalid IP Address" for SetDNSServerSearchOrder

When I try with the IPv4 address it succeeds to add the DNS server. But when I try to give the IPv6 address instead of IPv4 address it doesn't work.

  1. Why it is not able to set the IPv6 address?
  2. What is the alternative for achiving this in IPv6 machine?

Below is the code snippet what I tried. Also tried giving IPAddress and string datatypes as the input to SetDNSServerSearchOrder.

PS C:\Users\Administrator> $NICs = Get-WmiObject Win32_NetworkAdapterConfiguration | Where {$_.IPEnabled -eq "TRUE" -and
 ($_.IPAddress -contains "1111:1111:1111:1111:1111:1111:1111:1114")}
PS C:\Users\Administrator> [System.Net.IPAddress]$IP="1111:1111:1111:1111:1111:1111:1111:1112"
PS C:\Users\Administrator> $IP


Address           :
AddressFamily     : InterNetworkV6
ScopeId           : 0
IsIPv6Multicast   : False
IsIPv6LinkLocal   : False
IsIPv6SiteLocal   : False
IPAddressToString : 1111:1111:1111:1111:1111:1111:1111:1112



PS C:\Users\Administrator> $NICs.SetDNSServerSearchOrder($IP)


__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     :
__DYNASTY        : __PARAMETERS
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
ReturnValue      : 70



PS C:\Users\Administrator> [string]$IP="1111:1111:1111:1111:1111:1111:1111:1112"
PS C:\Users\Administrator> $NICs.SetDNSServerSearchOrder($IP)


__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     :
__DYNASTY        : __PARAMETERS
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
ReturnValue      : 70



PS C:\Users\Administrator> $IP
1111:1111:1111:1111:1111:1111:1111:1112
PS C:\Users\Administrator> $NICs


DHCPEnabled      : True
IPAddress        : {fe80::24b7:d14e:fd15:bd2b, 1111:1111:1111:1111:1111:1111:1111:1114}
DefaultIPGateway :
DNSDomain        :
ServiceName      : e1cexpress
Description      : Intel(R) 82579LM Gigabit Network Connection
Index            : 10



PS C:\Users\Administrator>

Below is the screenshot after running these commands.

enter image description here

Also searched in Google and can't find a solution. :-(

OS version: windows server 2008 r2

Powershell version: Powershell 2.0

Solution shall be unique so that I can use for both IPv4 and IPv6 systems.

It would be great if anyone can help in this regard.

M.C.Rohith
  • 3,730
  • 2
  • 20
  • 26
  • `SetDNSServerSearchOrder` seems to expect an array of strings...Not sure what happens if you pass it a single string. – Michael Hampton Feb 27 '14 at 21:07
  • As I don't require alternate DNS server. I didn't pass the other IP. But earlier with IPv4 systems, I am able to set the DNS with the single IP in the same way as I did in this thread. – M.C.Rohith Feb 28 '14 at 04:41
  • Link http://msdn.microsoft.com/en-us/library/windows/desktop/aa822883(v=vs.85).aspx explains that only IPAddress property support IPv6 but not the SetDNSServerSearchOrder method. – M.C.Rohith Mar 05 '14 at 04:49

2 Answers2

2
  1. Not sure - in Win2012 you sidestep that whole issue by using dedicated cmdlets for network management

    Set-DnsClientServerAddress -InterfaceIndex $($Nics.InterfaceIndex) -ServerAddresses $IP
    
  2. Use netsh

    $NICs = Get-WmiObject Win32_NetworkAdapterConfiguration | Where {$_.IPEnabled -eq "TRUE" -and
    ($_.IPAddress -contains "1111:1111:1111:1111:1111:1111:1111:1114")}
    $IP="1111:1111:1111:1111:1111:1111:1111:1112"
    netsh interface IPv6 set dnsservers name=$($Nics.InterfaceIndex) static $IP primary
    

And this can be adapted to accomodate ipv4 too:

    if($IP.contains(":")){
        netsh interface IPv6 set dnsservers name=$($Nics.InterfaceIndex) static $IP primary
    }
    elseif($IP.contains(".")){
        netsh interface IPv4 set dnsservers name=$($Nics.InterfaceIndex) static $IP primary
    }
    else{
         Write-Host ("Invalid IP:" + $IP)
    }
Raf
  • 9,681
  • 1
  • 29
  • 41
  • Also I need to support in windows 2K8 R2. I will check that... seems to work. I am also looking at the similar post http://serverfault.com/questions/380524/how-to-automate-dns-server-reconfiguration-for-tcp-ipv4-and-tcp-ipv6-in-windows – M.C.Rohith Feb 28 '14 at 11:42
  • Can you add how set this in win 2012 this will help others whoever looking for solution in windows server 2012. Also I need a unique solution that can achieve with IPv4 and IPv6 systems. – M.C.Rohith Feb 28 '14 at 12:41
1

I had simmilar case, where I set via WMI

...| %{$_.SetDNSServerSearchOrder("10.10.10.10, 10.10.10.11") }

just replace

$dns = "10.10.10.10", "10.10.10.11"
...| %{$_.SetDNSServerSearchOrder($DNS) }