Simple problem with format (noob)

Welcome Forums General PowerShell Q&A Simple problem with format (noob)

This topic contains 5 replies, has 3 voices, and was last updated by

 
Participant
5 years, 6 months ago.

  • Author
    Posts
  • #10969

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 48
    Rank: Member

    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

    Participant
    Points: 48
    Rank: Member
  • #10974

    Participant
    Points: 0
    Rank: Member

    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

    Member
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    Thanks Dave, that did the trick!

The topic ‘Simple problem with format (noob)’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort