none
Script add dns RRS feed

  • Question

  • Hello! I need help with some script. Script add DNS and work works great. But it is necessary that it reads the current DNS records and adds records specified in $ DNSServers, rather than overwriting it. Perhaps the logic of the script and will have a rewrite, but it is necessary that the primary and secondary DNS values ​​remain unchanged. Plz. Help! Thx.

    $computer = get-content C:\1.txt
    $NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer |where{$_.IPEnabled -eq “TRUE” -and $_.DNSServerSearchOrder -ne $null}
      Foreach($NIC in $NICs) {
    $DNSServers = “198.102.234.125",”198.102.234.126"
     $NIC.SetDNSServerSearchOrder($DNSServers)
    }


    • Edited by Sel83 Thursday, August 3, 2017 12:46 PM
    • Moved by Bill_Stewart Wednesday, September 13, 2017 9:40 PM This is not "scripts on demand"
    Thursday, August 3, 2017 12:45 PM

All replies

  • Not sure if this will work but you maybe able to do

    $CurrentDNSServers = $NIC.DNSServerSearchOrder

    $DNSServers = $CurrentDNSServers + "198.102.234.125","198.102.234.126"



    • Edited by simbrook2 Thursday, August 3, 2017 1:42 PM
    Thursday, August 3, 2017 1:10 PM
  • Get the current DNS Servers IP Addresses first, then join them with the ones you want to add additionally:

    $computer = hostname
    $NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer |where{$_.IPEnabled -eq “TRUE” -and $_.DNSServerSearchOrder -ne $null}
      Foreach($NIC in $NICs) {
    $DNSServers = $NIC.DNSServerSearchOrder[0] + ", " + $NIC.DNSServerSearchOrder[1] + “, 198.102.234.125, 198.102.234.126"
     $NIC.SetDNSServerSearchOrder($DNSServers)
     }


    Ajude a melhorar a eficiência nas buscas, se foi útil, classifique. {http://rafaelcmachado.spaces.live.com} Rafael Carneiro Machado

    Thursday, August 3, 2017 1:54 PM
  • Get the current DNS Servers IP Addresses first, then join them with the ones you want to add additionally:

    $computer = hostname
    $NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer |where{$_.IPEnabled -eq “TRUE” -and $_.DNSServerSearchOrder -ne $null}
      Foreach($NIC in $NICs) {
    $DNSServers = $NIC.DNSServerSearchOrder[0] + ", " + $NIC.DNSServerSearchOrder[1] + “, 198.102.234.125, 198.102.234.126"
     $NIC.SetDNSServerSearchOrder($DNSServers)
     }


    Ajude a melhorar a eficiência nas buscas, se foi útil, classifique. {http://rafaelcmachado.spaces.live.com} Rafael Carneiro Machado

    i try it, dont work (
    Thursday, August 3, 2017 2:20 PM
  • what happens when you run

    $NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername localhost |where{$_.IPEnabled -eq “TRUE” -and $_.DNSServerSearchOrder -ne $null}
    $CurrentDNSServers = $NICs.DNSServerSearchOrder
    $DNSServers = $CurrentDNSServers + "198.102.234.125","198.102.234.126"
    $DNSServers

    Thursday, August 3, 2017 2:37 PM
  • Get the current DNS Servers IP Addresses first, then join them with the ones you want to add additionally:

    $computer = hostname
    $NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer |where{$_.IPEnabled -eq “TRUE” -and $_.DNSServerSearchOrder -ne $null}
      Foreach($NIC in $NICs) {
    $DNSServers = $NIC.DNSServerSearchOrder[0] + ", " + $NIC.DNSServerSearchOrder[1] + “, 198.102.234.125, 198.102.234.126"
     $NIC.SetDNSServerSearchOrder($DNSServers)
     }


    Ajude a melhorar a eficiência nas buscas, se foi útil, classifique. {http://rafaelcmachado.spaces.live.com} Rafael Carneiro Machado

    i try it, dont work (
    $computer = hostname
    $NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer |where{$_.IPEnabled -eq “TRUE” -and $_.DNSServerSearchOrder -ne $null}
      Foreach($NIC in $NICs) {
    $DNSServers = $NIC.DNSServerSearchOrder[0],  $NIC.DNSServerSearchOrder[1], "198.102.234.125", "198.102.234.126"
     $NIC.SetDNSServerSearchOrder($DNSServers)
     }



    ну я такой прихожу и мур, мур, мур!

    Thursday, August 3, 2017 2:47 PM