删除特定的CName条目[PowerShell]

问题描述:

我试图在我们的内部DNS中自动创建和删除CName记录。我们正在运行Windows Server 2012 R2并使用PowerShell DNS服务器cmdlet。删除特定的CName条目[PowerShell]

查询和CNAMES的创作是没有问题的,这条线将创建web.test.dev.contoso.com CNAME并将其链接到dev01.contoso.com. AName进入

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

此行检索web.test.dev.contoso.com CNAME链接到该dev01.contoso.com. AName

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

但删除CNAME记录是问题,我可以检索的CNAME并将其传递到Remove-DnsServerResourceRecord cmdlet的likeso:

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 

有没有人能够使用基于条目的值删除,DnsServerResourceRecord cmdlet删除CNAME记录或者它只是删除所有CNAMES具有特定名称?

编辑:按照弗罗德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 
+0

如果你只是使用原始命令会发生什么,没有任何流水线? (错误提示管道问题) –

你不能用管道(输入对象)使用-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>]

+1

由SO再次保存,谢谢Frode F! – ShaneC