Author Posts

October 22, 2013 at 1:18 am

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?

October 22, 2013 at 4:49 am

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.

October 22, 2013 at 4:57 am

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.

October 22, 2013 at 4:57 am

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

October 22, 2013 at 5:01 am

Thanks Dave, that did the trick!