title: Error editing Windows DNS
body: <p>I've read on several different reliable tech blogs and discussions that the following code should allow me to target my NICs with static IPs that are using specific DNS servers, and update the servers they're using.</p>
  
  <pre><code>$NICs = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "DHCPEnabled='FALSE'" |
          Select-Object -Property DNSServerSearchOrder |
          Where {
              $_.DNSServerSearchOrder -contains "OldDNS1" -or
              $_.DNSServerSearchOrder -contains "OldDNS2"
          }
  
  foreach ($NIC in $NICs) {
      $NIC.SetDNSServerSearchOrder("NewDNS1","NewDNS2")
  }
  </code></pre>
  
  <p>However, when I run that code I get the following error:</p>
  
  <pre class="lang-none prettyprint-override"><code>Method invocation failed because [Selected.System.Management.ManagementObject]
  doesn't contain a method named 'SetDNSServerSearchOrder'. 
  At line:2 char:33
  + $NIC.SetDNSServerSearchOrder &lt;&lt;&lt;&lt; ("NewDNS1","NewDNS2")
      + CategoryInfo          : InvalidOperation: (SetDNSServerSearchOrder:String) [], RuntimeException
      + FullyQualifiedErrorId : MethodNotFound
  </code></pre>
  
  <p>I haven't been able to figure out or properly find a solution and I'm not sure what I'm missing. Does anyone have any suggestions?</p>
  
  <p>Edit: After @FoxDeploy's suggestion I was getting another error:</p>
  
  <pre class="lang-none prettyprint-override"><code>Cannot find an overload for "SetDNSServerSearchOrder" and the argument count: "2".
  At line:2 char:33
  + $NIC.SetDNSServerSearchOrder &lt;&lt;&lt;&lt; ("172.16.1.50","172.16.210.53")
      + CategoryInfo          : NotSpecified: (:) [], MethodException
      + FullyQualifiedErrorId : MethodCountCouldNotFindBest
  </code></pre>
  
  <p>I had to change:</p>
  
  <pre><code>$NIC.SetDNSServerSearchOrder("NewDNS1","NewDNS2")
  </code></pre>
  
  <p>It is now:</p>
  
  <pre><code>$NIC.SetDNSServerSearchOrder($("NewDNS1","NewDNS2"))
  </code></pre>