【问题标题】:Delete specific CName entry [PowerShell]删除特定的 CName 条目 [PowerShell]
【发布时间】: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


【解决方案1】:

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

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

Syntax:

参数集:InputObject
删除-DnsServerResourceRecord [-ZoneName] [-CimSession ] [-ComputerName ] [-Force] [-InformationAction {静默继续 | 停止 |继续 |查询 |忽略 |暂停}] [-InformationVariable ] [-PassThru] [-ThrottleLimit ] [-ZoneScope ] [-Confirm] [-WhatIf] [ ] [ ]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    • 1970-01-01
    • 2019-09-23
    • 2012-10-26
    相关资源
    最近更新 更多