update PTR record

May 11, 2011 at 2:51 PM


i found the DnsShell and i'm now exploring it.
I'm a little confuse about  get-DnsRecord and Set-DnsRecord

i'm able to get data with get-DnsRecord -name "computer.company.local" -RecordType A -Server "ServerName". it returns the correct information. However I can't get the same type of information of PTR RecordType: get-DnsRecord -name "" -RecordType PTR -Server "ServerName" -ZoneName "1.168.192.in-addr.arpa"

All of this because I need to pass the Identity to Set-DnsRecord. It works very fine with A Record (get-DnsRecord -name "computer.company.local" -RecordType A -Server "ServerName" |Set-DnsRecord -Address "NewIPAddress" and I need it to PTR type as also.

Thank you in advance

May 11, 2011 at 3:01 PM

Ah yes, I never thought to account for that. PTR records are written in reverse, and name matches the actual record name (not the IP representation).

That makes it:

Get-DnsRecord "150" -RecordType PTR -Server "ServerName" -ZoneName "1.168.192.in-addr.arpa"

Then it should find the right answer.

However, you need to purge the old PTR record and create a new one, there's no way to rename a record.


# Drop the old record
Get-DnsRecord "150" -RecordType PTR -Server "ServerName" -ZoneName "1.168.192.in-addr.arpa" | Remove-DnsObject

# Add the new record
New-DnsRecord -RecordType PTR -Server "Servername" -ZoneName "1.168.192.in-addr.arpa


May 11, 2011 at 4:10 PM

worked just fine.

Thank you

Sep 12, 2011 at 11:48 PM

Now, I noticed something interesting... you have the line:

Get-DnsRecord "150" -RecordType PTR -Server "ServerName" -ZoneName "1.168.192.in-addr.arpa"

If you have an address of "1" for the reverse of as an entry... your PS line would look like this:

Get-DnsRecord "1" -RecordType PTR -Server "ServerName" -ZoneName "1.168.192.in-addr.arpa"

However, when i ran this, it brought back ALL records that had a "1" at the beginning of the record (example:,,, etc.)

Anyway I can make sure if I need to put a "1" or single digit in there... it only deletes that record if i run the command below, and not ALL of the other records too?

Get-DnsRecord "1" -RecordType PTR -Server "ServerName" -ZoneName "1.168.192.in-addr.arpa" | Remove-DnsObject

Sep 16, 2011 at 3:21 PM

Wildcard by default, I need to revisit that and modify the behaviour a little I think.

I'll add it to the list for the next release.

Thanks for your feedback :)


May 10, 2012 at 2:38 PM

This is a real bummer.  It makes it pretty unusable to update PTR records.  There is no way to delete them without removing all similar records.

Oct 25, 2013 at 8:38 PM
TeflonJim wrote:
Wildcard by default, I need to revisit that and modify the behaviour a little I think. I'll add it to the list for the next release. Thanks for your feedback :) Chris
Has this been corrected? I am thinking not. I need to verify a PTR record exist. I guess I can break down the response and do an octet comparison, but would be cool if this didn't wildcard here.


$ptr = (Get-DnsRecord $ip[3] -RecordType PTR -Server $DnsServer -ZoneName ($ip[2] + "." + $ip[1] + "." + $ip[0] + ".in-addr.arpa"));

(This was a reply to a query.)
Oct 30, 2013 at 4:23 PM
I am getting inconsistent results with PTR records. Since I was trying to use this to test for the existence of PTR records I can't see it being much use.

Here you can see a normal reply, wildcard search aside, it is behaving correctly. IP =
Get-DnsRecord 50 -RecordType PTR -Server $DnsServer -ZoneName 249.249.10.in-addr.arpa

Name                              RecordType                        TTL                               RecordData                        TimeStamp                        
----                              ----------                        ---                               ----------                        ---------                      PTR                               1200                              blah.blah.com.           10/28/2013 12:00:00 AM          PTR                               1200                              blah.blah.com.           10/28/2013 12:00:00 AM
Here is total gibberish where it lists every record in the zone. IP =
Get-DnsRecord 49 -RecordType PTR -Server $DnsServer -ZoneName 249.249.10.in-addr.arpa

Name                              RecordType                        TTL                              
----                              ----------                        ---                              PTR                               3600                            PTR                               1200                           PTR                               3600                           PTR                               3600                           PTR                               3600                           PTR                               3600                           PTR                               3600                           PTR                               3600                             
Oct 30, 2013 at 4:47 PM
Edited Oct 30, 2013 at 4:49 PM
First of all, I agree this CmdLet isn't intuitive and may be extremely confusing. Hell I have to look up how it works and I wrote the thing.

The wildcard search uses the value entered as a regular expression, it validates the OwnerName property (from WMI) like this:
if (NameRegEx.IsMatch((String)wmiRecord.Properties["OwnerName"].Value))
The OwnerName property includes the zone suffix. e.g.
And since we're using a regex we can match the "Name" value anywhere in the OwnerName string.

With the current version you still have two choices:

Work with the parameter as it stands and feed a regex
Get-DnsRecord '^49\.' -RecordType PTR -Server $DnsServer -ZoneName 249.249.10.in-addr.arpa
Where ^ matches the start of the string, therefore the first label, and . a literal period (.) instead of any character (the meaning of . in regex2. ).

Use the WMI filter parameter

The behaviour I've elected to use can be overridden. You can filter on any WMI field as long as the interface supports it.

The equivalent of the search above is this:
Get-DnsRecord -RecordType PTR -Server $DnsServer -Filter "OwnerName=''"
Clearly that's not an easy option unless you're willing to dig into the underlying interface.

This feedback is, of course, valuable so thank you. If I manage to get far enough into the new version I'll revisit the design for this CmdLet entirely.

Nov 25, 2013 at 4:41 PM
Thanks Chris,
Since I have the entire IP for this project using the ownername filter works just fine. I can easily build my query for that and then pick apart the return Hostname and compare it to my initial value. Not sure I would have figured that out so thanks for the reply.