new-dnsrecord $myString

Apr 12, 2012 at 2:12 PM

I am new to powershell scripting, so pardon my ignorance but I get the error below everytime I try the following:

$myString="-Name -RecordType PTR -ZoneName -Hostname -Server abc-wdc-123"

new-dnsrecord $myString

[PS] C:\WINDOWS\system32\WindowsPowerShell\v1.0>new-dnsrecord $myString

New-DnsRecord : A positional parameter cannot be found that accepts argument '='-Name -RecordType PTR -ZoneName -Hostname -Server abc-wdc-123'

At line:1 char:14
+ new-dnsrecord <<<<  $myString
    + CategoryInfo          : InvalidArgument: (:) [New-DnsRecord], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,DnsShell.PowerShell.CmdLet.NewDnsRecord

It is part of a larger script, where I read in an ip address and hostname, create the reverse PTR entry by doing a split and then assign the new record string to the variable $myString.  Can you not pass variables to the dnsshell modules?

Apr 12, 2012 at 6:03 PM

You can, but you'd need to use Splatting in much the same way as you'd have to do this with other PS CmdLets, this isn't unique to my module.

For example:

$Params = @{}
$Params.Add("Name", "")
$Params.Add("RecordType", "PTR")

# and so on
New-DnsRecord @Params

For further information, see:


Apr 13, 2012 at 8:11 PM

Thank you very much, this worked perfectly, even with variables instead of text.

One last question.  New-DnsZone doesn't seem to accept a DynamicUpdate Parameter, but Get-DnsZone lists this attribute (SecureOnly is what I want to set this parameter to).  Is there a way to do this in the New-DnsZone command?


Apr 14, 2012 at 9:00 AM

Not with New-DnsZone, no. It's a wrapper for the WMI interface responsible for creating zones. It's functionality that's supposed to live with Set-DnsZone. Unfortunately I haven't had time to work on my module lately, actual work is in the way.