如何使用PowerShell删除单个N​​APTR记录? [英] How to use PowerShell to delete a single NAPTR record?

查看:59
本文介绍了如何使用PowerShell删除单个N​​APTR记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用GUI创建了新的NAPTR记录.但是,我想使用PowerShell删除其中之一.

I created a new NAPTR records using the GUI. However I'd like to delete one of them using PowerShell.

我可以证明有2条记录:

I can prove there are 2 records:

> Get-DnsServerResourceRecord -ZoneName "example.com" -Name "foo" -RRType naptr

HostName                  RecordType Type       Timestamp            TimeToLive      RecordData
--------                  ---------- ----       ---------            ----------      ----------
foo                       NAPTR      35         0                    01:00:00
foo                       NAPTR      35         0                    01:00:00

> $OldObj = Get-DnsServerResourceRecord -ZoneName "example.com" -Name "foo" -RRType naptr
> $OldObj[0].RecordData.Data
010001000155036F6E65036F6E6500
> $OldObj[1].RecordData.Data
0200020001550374776F0374776F00
> $OldObj[2].RecordData.Data
>

如果我尝试删除记录,则可以以交互方式进行:

If I try to delete the records, I can do it interactively:

> Remove-DnsServerResourceRecord -ZoneName "example.com" -Name "foo" -RRType NAPTR

Confirm
Removing DNS resource record set by name foo of type NAPTR from zone example.com on TOMDEV server. Do you want to continue?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y

不幸的是,这两个记录都被删除!

Sadly that deletes both of the records!

如果我改为尝试删除该对象怎么办?

What if I try to remove the object, instead?

> $OldObj[1] | Remove-DnsServerResourceRecord -ZoneName "example.com" -Name "foo"

Confirm
Removing DNS resource record set by name foo of type NAPTR from zone example.com on TOMDEV server. Do you want to
continue?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
> Get-DnsServerResourceRecord -ZoneName "example.com" -Name "foo" -RRType naptr
Get-DnsServerResourceRecord: Failed to get foo record in example.com zone on TOMDEV server.

哦,不!那删除了两条记录!

Oh no! That deleted both records!

我可以指定一条记录到 Remove-DnsServerResourceRecord 吗?

Can I specify a single record to Remove-DnsServerResourceRecord?

这是我尝试过的:

这完全被拒绝了:

> Remove-DnsServerResourceRecord -ZoneName "example.com" -Name "foo" -RRType NAPTR -RecordData "0200020001550374776F0374776F00"
Remove-DnsServerResourceRecord: InputObject for resource record has an invalid value. Failed to remove the resource record on TOMDEV server. Please check extended error for additional details.

如果我尝试捕获一条记录并将其通过管道传送到 Remove-,则会删除两条记录:

If I try to capture the one record and pipe it to Remove-, that removes both records:

# First, we single out exactly one record:
> Get-DnsServerResourceRecord -ZoneName "example.com" -Name "foo" -RRType NAPTR | Where-Object {$_.HostName -eq "foo" -and $_.RecordData.Data -eq "0200020001550374776F0374776F00" }

HostName                  RecordType Type       Timestamp            TimeToLive      RecordData
--------                  ---------- ----       ---------            ----------      ----------
foo                       NAPTR      35         0                    01:00:00

>
# That worked! Let's use that query and pipe it to Remove!
> Get-DnsServerResourceRecord -ZoneName "example.com" -Name "foo" -RRType NAPTR | Where-Object {$_.HostName -eq "foo" -and $_.RecordData.Data -eq "0200020001550374776F0374776F00" } | Remove-DnsServerResourceRecord -ZoneName "example.com" -Name "foo" -Force
# Nope, that removed both records!
> Get-DnsServerResourceRecord -ZoneName "example.com" -Name "foo" -RRType naptr
Get-DnsServerResourceRecord: Failed to get foo record in example.com zone on TOMDEV server.
>

这不是删除"foo"处的所有内容,只是NAPTR记录在那里.(实际上,该消息说的是记录集"(复数),而不是记录".

It isn't removing everything at "foo", just the NAPTR records there. (In fact, the message says "record sets" (plural), not "record".

让我们证明,通过创建A记录加上2个NAPTR记录,所有记录均位于标签"foo"处.我们将看到相同的问题:

Let's prove that by creating an A record plus 2 NAPTR records all at label "foo". We'll see the same problem:

> Get-DnsServerResourceRecord -ZoneName "example.com" -Name "foo"

HostName                  RecordType Type       Timestamp            TimeToLive      RecordData
--------                  ---------- ----       ---------            ----------      ----------
foo                       A          1          0                    01:00:00        4.4.4.4
foo                       NAPTR      35         0                    01:00:00
foo                       NAPTR      35         0                    01:00:00

> $OldObj = Get-DnsServerResourceRecord -ZoneName "example.com" -Name "foo" -RRType naptr
> $OldObj[0].RecordData.Data
010001000155036F6E65036F6E6500
> $OldObj[1].RecordData.Data
0200020001550374776F0374776F00
> $OldObj[2].RecordData.Data
> Get-DnsServerResourceRecord -ZoneName "example.com" -Name "foo" -RRType NAPTR | Where-Object {$_.HostName -eq "foo" -and $_.RecordData.Data -eq "0200020001550374776F0374776F00" } | Remove-DnsServerResourceRecord -ZoneName "example.com" -Name "foo"

Confirm
Removing DNS resource record set by name foo of type NAPTR from zone example.com on TOMDEV server. Do you want to
continue?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
> Get-DnsServerResourceRecord -ZoneName "example.com" -Name "foo"

HostName                  RecordType Type       Timestamp            TimeToLive      RecordData
--------                  ---------- ----       ---------            ----------      ----------
foo                       A          1          0                    01:00:00        4.4.4.4

>

如何删除单个N​​APTR记录?

How can I delete a single NAPTR record?

推荐答案

如果您要删除其中之一,则不要紧要删除其中之一,也要说您也尝试过此操作:

If you are saying you want to delete one of them, and it does not matter which one, are saying you also tried this:

Get-DnsServerResourceRecord -ZoneName "example.com" -Name "foo" -RRType NAPTR | 
Where-Object {
    $PSItem.HostName -eq "foo" -and 
    $PSItem.RecordData.Data -eq "0200020001550374776F0374776F00" 
} |
Select-Object -First 1 |
Remove-DnsServerResourceRecord -WhatIf

这篇关于如何使用PowerShell删除单个N​​APTR记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆