Delete specific CName entry [PowerShell]
<p>I'm trying to automate the creation and deletion of CName records in our internal DNS. We are running Windows Server 2012 R2 and are using the PowerShell DNS Server cmdlets.</p>

<p>The querying and creation of CNames are not a problem, this line creates the <code>web.test.dev.contoso.com</code> CName and links it to the <code>dev01.contoso.com.</code> AName entry</p>

<pre><code>Add-DnsServerResourceRecordCName -ZoneName "contoso.com" -HostNameAlias "dev01.contoso.com." -Name "web.test.dev"
</code></pre>

<p>This line retrieves the <code>web.test.dev.contoso.com</code> CName that is linked to the <code>dev01.contoso.com.</code> AName</p>

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

<p>But deleting the CName record is the issue, I can retrieve the CName and pass it to the <code>Remove-DnsServerResourceRecord</code> cmdlet likeso:</p>

<pre><code>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"
</code></pre>

<p>But I get this error:</p>

<pre><code>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
</code></pre>

<p>Has anyone been able to delete a CName record using the Remove-DnsServerResourceRecord cmdlet based on the entry's values or does it just delete all CNames with a certain name?</p>

<p><strong>EDIT</strong>: As per Frode F's answer, the final command is:</p>

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