删除特定的 CName 条目 [PowerShell]

Delete specific CName entry [PowerShell]

我正在尝试在我们的内部 DNS 中自动创建和删除 CName 记录。我们是 运行 Windows Server 2012 R2 并且正在使用 PowerShell DNS 服务器 cmdlet。

CName 的查询和创建没有问题,此行创建 web.test.dev.contoso.com CName 并将其链接到 dev01.contoso.com. AName 条目

Add-DnsServerResourceRecordCName -ZoneName "contoso.com" -HostNameAlias "dev01.contoso.com." -Name "web.test.dev"

此行检索链接到 dev01.contoso.com. AName

web.test.dev.contoso.com CName
Get-DnsServerResourceRecord -RRType CName -ZoneName "contoso.com" | ? {$_.RecordData.HostNameAlias -eq "dev01.contoso.com." -and $_.HostName -eq "web.test.dev"

但删除 CName 记录是个问题,我可以检索 CName 并将其传递给 Remove-DnsServerResourceRecord cmdlet,如下所示:

Get-DnsServerResourceRecord -RRType CName -ZoneName "contoso.com" | ? {$_.RecordData.HostNameAlias -eq "dev01.contoso.com." -and $_.HostName -eq "web.test.dev" | Remove-DnsServerResourceRecord -ZoneName $zoneName -RRType "CName"

但是我得到这个错误:

The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take 
pipeline input.
    + CategoryInfo          : InvalidArgument: (DnsServerResourceRecord:PSObject) [Remove-DnsServerResourceRecord], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Remove-DnsServerResourceRecord

有没有人能够根据条目的值使用 Remove-DnsServerResourceRecord cmdlet 删除 CName 记录,或者只是删除具有特定名称的所有 CName?

编辑:根据 Frode F 的回答,最终命令是:

Get-DnsServerResourceRecord -RRType CName -ZoneName "contoso.com" | ? {$_.RecordData.HostNameAlias -eq "dev01.contoso.com." -and $_.HostName -eq "web.test.dev" | Remove-DnsServerResourceRecord -ZoneName $zoneName -Force

您不能将 -RRType "CName" 与管道(输入对象)一起使用。删除它,它应该可以工作。

只有 zonename 和 zonescope 是使用管道时有效的可选参数。

Syntax:

Parameter Set: InputObject
Remove-DnsServerResourceRecord [-ZoneName] <String> [-CimSession <CimSession[]> ] [-ComputerName <String> ] [-Force] [-InformationAction <System.Management.Automation.ActionPreference> {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend} ] [-InformationVariable <System.String> ] [-PassThru] [-ThrottleLimit <Int32> ] [-ZoneScope <System.String> ] [-Confirm] [-WhatIf] [ <CommonParameters>] [ <WorkflowParameters>]