Simple problem with format (noob)

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of ReMarkIT ReMarkIT 3 years, 6 months ago.

  • Author
    Posts
  • #10969
    Profile photo of ReMarkIT
    ReMarkIT
    Participant

    Hi,

    I am trying this very simple script yet it fails due to formatting:


    Invoke-Command -Computername nlamsdc03 -ScriptBlock {cmd.exe /c dnscmd nlamsdc03 /RecordDelete acme.com webmail-test A /f}
    $switch_ip = "10.1.1.101"
    Invoke-Command -Computername nlamsdc03 -ScriptBlock {cmd.exe /c dnscmd nlamsdc03 /RecordAdd acme.com webmail-test 60 A $switch_ip}

    The line of code returns: Command failed: DNS_ERROR_RECORD_FORMAT 9702 0x25E6

    $switch_ip is a string but apparently the dnscmd does not like it. What should i do?

  • #10972
    Profile photo of Vern Anderson
    Vern Anderson
    Participant

    I think your DNSCMD is missing the record type.

    Looks like you're deleting a CNAME so you may need to specify the record type. Looking back at scripts I had written like this I was dealing with A records so I don't know for sure but that's what appears to be wrong.

    use DNSCMD /? to check the syntax for deleting a CNAME (alias) record.

  • #10973
    Profile photo of Vern Anderson
    Vern Anderson
    Participant
  • #10974
    Profile photo of ReMarkIT
    ReMarkIT
    Participant

    Hi,

    The record type is specified in the command, i am deleting an A record and the creating it with a different IP.

    From the command above, deleting the A record works fine but it is the creation that fails. If i replace the variable $switch_ip by the IP it works fine:

    Example

    Invoke-Command -Computername nlamsdc03 -ScriptBlock {cmd.exe /c dnscmd nlamsdc03 /RecordAdd acme.com webmail-test 60 A 10.1.1.101}

    so i guess it is just a format error.

  • #10975
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    The problem here is that the $switch_ip variable doesn't exist in the scope of the script block that you're executing on the remote machine. Try passing it as an argument, like this:

    $switch_ip = "10.1.1.101"
    Invoke-Command -Computername nlamsdc03 -ScriptBlock { cmd.exe /c dnscmd nlamsdc03 /RecordAdd acme.com webmail-test 60 A $args[0] } -ArgumentList $switch_ip
    
  • #10978
    Profile photo of ReMarkIT
    ReMarkIT
    Participant

    Thanks Dave, that did the trick!

You must be logged in to reply to this topic.