none
Powershell Set-DhcpServerv4OptionValue works with IP not string RRS feed

  • Question

  • ok so this works perfect.

    Set-DhcpServerv4OptionValue -ScopeId $ScopeId -DnsServer 10.244.10.70,172.17.17.3   -Force

    This does not work.

    Set-DhcpServerv4OptionValue -ScopeId $ScopeId -DnsServer $OptionDNSServers   -Force 
    i know $OptionDNSServers  = "10.244.10.70,172.17.17.3"

    Any thoughts?

    Thanks


    Lishron

    Monday, June 29, 2015 7:13 PM

Answers

  • $OptionDNSServers  = "10.244.10.70,172.17.17.3" -split ','
    • Marked as answer by Lishron Monday, June 29, 2015 7:45 PM
    Monday, June 29, 2015 7:42 PM

All replies

  • $OptionDNSServers  = '10.244.10.70', '172.17.17.3'
    Monday, June 29, 2015 7:24 PM
  • That would work but i am pulling this from a CSV file that changes often.  The DNS servers are in a cell xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx

    I can do 

    $OptionDNSServers = $OptionDNSServers -replace ",","`",`""
    $OptionDNSServers = "`"$OptionDNSServers`""

    But it does not change the error 

    et-DhcpServerv4OptionValue : Cannot process argument transformation on parameter 'DnsServer'. Cannot convert value 
    ""10.241.84.8","10.244.11.144"" to type "System.Net.IPAddress[]". Error: "Cannot convert value ""10.241.84.8","10.244.11.144"" to type 
    "System.Net.IPAddress". Error: "An invalid IP address was specified.""


    Lishron

    Monday, June 29, 2015 7:36 PM
  • $OptionDNSServers  = "10.244.10.70,172.17.17.3" -split ','
    • Marked as answer by Lishron Monday, June 29, 2015 7:45 PM
    Monday, June 29, 2015 7:42 PM
  • That is it.  

    I swear i was coming back to post the answer but you beat me to it.

    Thanks!!

    if ($OptionDNSServers -ne "NA") {Set-DhcpServerv4OptionValue -ScopeId $ScopeId -DnsServer $OptionDNSServers.Split(",") -Force }



    Lishron

    Monday, June 29, 2015 7:47 PM
  • -DnsServer is defined as a string array [string[]] look it up.  You are sending it a comma delimited string.


    \_(ツ)_/

    Monday, June 29, 2015 8:02 PM
  • Sorry i don't follow JRV?

    It seems to be working but is this causing issues I  don't see or is there a better way to do it?

    Thank you


    Lishron

    Tuesday, June 30, 2015 2:41 PM
  • This is a string:

     $OptionDNSServers  = '10.244.10.70,172.17.17.3'

    THis is an array:

     $OptionDNSServers  = '10.244.10.70','172.17.17.3'

    This is an array:

    Set-DhcpServerv4OptionValue  -DnsServer 10.244.10.70, 172.17.17.3


    \_(ツ)_/

    Tuesday, June 30, 2015 2:44 PM
  • Thank you


    Lishron

    Tuesday, June 30, 2015 2:47 PM