none
Need help with this code.

    Question

  • workflow set-dnsclientserv
    {
    param(
    [parameter(Mandatory=$True)]
    [string]$DnsClientServerAddress1,

    [parameter(Mandatory=$True)]
    [string]$DnsClientServerAddress2,

    [parameter(Mandatory=$True)]
    [string]$servers,

    [Parameter(Mandatory=$true)]
    [System.Management.Automation.PSCredential]$credential
    )


    inlinescript
    {
        Invoke-Command -ComputerName (Get-Content $using:servers) -Credential $using:credential -ArgumentList $using:DnsClientServerAddress1,$using:DnsClientServerAddress2 -scriptblock {
            Set-DnsClientServerAddress -InterfaceAlias Admin -ServerAddresses $args[0],$args[1] -PassThru}

    }

    }
    set-dnsclientserv -Verbose

    I get this error:

    Exception calling "EndProcessing" with "0" argument(s): "The member "ServerAddress" is not present."
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : ExtendedTypeSystemException
        + PSComputerName        : [localhost]

    Any idea how to fix it?


    99upgrade

    Thursday, November 14, 2013 10:28 AM

Answers

  • Set-DnsClientServerAddress -InterfaceAlias Admin -ServerAddresses args[0],$args[1]


    Try this:

    Set-DnsClientServerAddress -InterfaceAlias Admin -ServerAddresses @($args[0],$args[1])


    I'm the most humble person you've ever met.


    • Edited by James Keeler Thursday, November 14, 2013 1:47 PM Clarification
    • Marked as answer by 99upgrade Thursday, November 14, 2013 2:14 PM
    Thursday, November 14, 2013 1:45 PM
  • Ok I realized why the error was coming up. Its my bad. The machines are ipv4 and ipv6 enabled and it was trying to set the dnsclient server for ipv6 and failied. The ipv4 part seems to have been working.

    99upgrade

    • Marked as answer by 99upgrade Thursday, November 14, 2013 2:14 PM
    Thursday, November 14, 2013 2:13 PM

All replies

  • Hello 99,

    if I remember my workflows correctly, all "-ComputerName" parameters turn into "-PSComputerName" parameters.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Thursday, November 14, 2013 1:42 PM
  • Set-DnsClientServerAddress -InterfaceAlias Admin -ServerAddresses args[0],$args[1]


    Try this:

    Set-DnsClientServerAddress -InterfaceAlias Admin -ServerAddresses @($args[0],$args[1])


    I'm the most humble person you've ever met.


    • Edited by James Keeler Thursday, November 14, 2013 1:47 PM Clarification
    • Marked as answer by 99upgrade Thursday, November 14, 2013 2:14 PM
    Thursday, November 14, 2013 1:45 PM
  • Why are you using a workflow here.  It serves no purpose.

    Why send two identical arguments. Why not just send one array.


    ¯\_(ツ)_/¯

    Thursday, November 14, 2013 1:57 PM
  • This command is not going to work unless you answer all prompts correctly:

    set-dnsclientserv


    ¯\_(ツ)_/¯

    Thursday, November 14, 2013 2:07 PM
  • Ok I realized why the error was coming up. Its my bad. The machines are ipv4 and ipv6 enabled and it was trying to set the dnsclient server for ipv6 and failied. The ipv4 part seems to have been working.

    99upgrade

    • Marked as answer by 99upgrade Thursday, November 14, 2013 2:14 PM
    Thursday, November 14, 2013 2:13 PM
  • I ran your script. I do not get any errors.  It works as expected.


    ¯\_(ツ)_/¯

    Thursday, November 14, 2013 2:17 PM
  • Jrv - There are more codes to be added to this. That's why I chose to create a workflow. The arguments are for primary and secondary dns server addresses.

    $DnsClientServerAddress1

    $DnsClientServerAddress2


    99upgrade

    Thursday, November 14, 2013 2:17 PM
  • Yeah. Those machines are ipv6 enabled and I only had ipv4 dns client server addresses which caused the errors. The code seems to be fine.

    99upgrade

    Thursday, November 14, 2013 2:18 PM