【问题标题】:Getting DNS Records from an Active Directory zone by IP Addresses通过 IP 地址从 Active Directory 区域获取 DNS 记录
【发布时间】:2020-06-05 16:54:45
【问题描述】:

我正在尝试对我的 DNS 区域运行以下查询,以根据 IP 地址返回记录,但运气不佳,脚本运行但只是空输出。

Get-Content ip.txt| ForEach {
    Get-DnsServerResourceRecord -zonename "xxx.global" | where-object {$_.RecordData.ipv4address -eq "$_"}
}

ip.txt文件的内容是这样的:

"10.32.84.102"
"172.31.65.18"
"172.31.65.203"

我尝试修改运行正常的原始命令,但我想针对 IP 列表运行它..

Get-DnsServerResourceRecord -zonename "xxx.global" | where-object {$_.RecordData.ipv4address -eq "10.32.84.102"}

我做错了什么?

【问题讨论】:

    标签: powershell dns active-directory zone


    【解决方案1】:

    您正在使用 $_ 来引用 Where-Object 中的不同对象。

    where-object {$_.RecordData.ipv4address -eq "$_"}
                 ^^^^                           ^^^^
    

    $_ 一次只能设置为一个对象。如果你启动另一个管道,之前的值将会消失。

    你需要这样做:

    $IPs = Get-Content ip.txt
    
    foreach ($IP in $IPs) {
        Get-DnsServerResourceRecord -zonename "xxx.global" | where-object { $_.RecordData.ipv4address -eq $IP }
    }
    

    您可能还需要从 ip.txt 中删除双引号。 IP 是10.32.84.102,而不是"10.32.84.102"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-25
      • 2021-07-03
      • 2017-08-25
      • 2020-10-21
      • 2013-04-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多