【发布时间】:2016-04-26 08:28:24
【问题描述】:
我正在尝试在我们的内部 DNS 中自动创建和删除 CName 记录。我们正在运行 Windows Server 2012 R2 并使用 PowerShell DNS 服务器 cmdlet。
CNames的查询和创建没有问题,这一行创建了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
【问题讨论】:
-
如果您只使用原始命令而不使用任何流水线会发生什么? (错误表明管道存在问题)
标签: powershell dns automation cname windows-server-2012-r2