首页 > 解决方案 > 如何通过 powershell 解析最新的 DNS CName 结果

问题描述

我正在尝试使用以下 powershell 脚本解析最新的 DNS CName。但是由于 DNS 服务器缓存,我得到的缓存主机名不是最新的 CName。有没有办法避免这种情况并获得最新的结果?(如在 digwebinterface.com 中)

之后我调用第三方 DNS 管理 API,它将修改或创建 DNS CName 映射。为此,我需要最新的 dns 数据。

#resolve the dns host name
$resolvedCName = Resolve-DnsName -Name $vanityHostName -DnsOnly -Type CNAME | 
Select-Object -First 1 -Property Name,NameHost  

write-host $resolvedCName.NameHost

标签: powershelldns

解决方案


这不是 PowerShell 问题或错误。它是一个环境条件。

为什么你不只是清除缓存作为你正在做的事情的一部分?

您是说 DnsClientCache cmdlet 或 Ipconfig -FlushDNS 没有为您提供您所追求的东西吗?

Clear-DnsClientCache cmdlet删除 DNS 客户端缓存的所有内容。运行此 cmdlet 等效于运行 ipconfig /flushdns。

Get-Command -Name Clear-DnsClientCache | Format-Table -AutoSize

<#
CommandType     Name                   Version    Source 
-----------     ----                   -------    ------  
Function        Clear-DnsClientCache   1.0.0.0    DnsClient 
#>


# get function / cmdlet details
Get-Command -Name Clear-DnsClientCache -Syntax
(Get-Command -Name Clear-DnsClientCache).Parameters.Keys
Get-help -Name Clear-DnsClientCache -Full
Get-help -Name Clear-DnsClientCache -Online
Get-help -Name Clear-DnsClientCache -Examples


ipconfig /?

<#
USAGE:
    ipconfig [/allcompartments] [/? | /all | 
                                 /renew [adapter] | /release [adapter] |
                                 /renew6 [adapter] | /release6 [adapter] |
                                 /flushdns | /displaydns | /registerdns |
                                 /showclassid adapter |
                                 /setclassid adapter [classid] |
                                 /showclassid6 adapter |
                                 /setclassid6 adapter [classid] ]

where
    adapter             Connection name 
                       (wildcard characters * and ? allowed, see examples)

    Options:
        ...
       /flushdns        Purges the DNS Resolver cache.
       /registerdns     Refreshes all DHCP leases and re-registers DNS names
        …
#>

推荐阅读