我試圖在我們的內部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
如果你只是使用原始命令會發生什麼,沒有任何流水線? (錯誤提示管道問題) –