Aidan Finn, IT Pro 2024年08月28日
Script – Document All Azure Private DNS Zones
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文介绍了使用 PowerShell 脚本记录 Azure 私有 DNS 区域的步骤。该脚本可以获取每个区域的名称、订阅名称、资源组名称以及关联的虚拟网络名称,并将其写入 Markdown 表格中,方便用户进行复制粘贴和文档整理。

👨‍💻 该脚本首先获取所有 Azure 订阅,并使用 `Get-AzPrivateDnsZone` 命令获取每个订阅下的所有私有 DNS 区域。

🌐 对于每个区域,脚本使用 `Get-AzPrivateDnsVirtualNetworkLink` 命令获取与该区域关联的虚拟网络链接,并提取虚拟网络名称。

📝 脚本将区域名称、订阅名称、资源组名称和虚拟网络名称写入一个 Markdown 表格中,并将其保存到名为 `dnsLinks.md` 的文件中。

💡 脚本使用 `try...catch` 语句来处理可能的错误,并使用 `break` 语句跳过特定订阅。

🚀 该脚本可以快速方便地记录 Azure 私有 DNS 区域信息,并提供清晰易懂的表格格式,方便用户进行文档整理和维护。

I found myself in a situation where I needed to document a lot of Azure Private DNS Zones. I needed the following information:

The list was long so a copy and paste from the Azure Portal was going to take too long. Instead, I put a few minutes into a script to do the job – it even writes the content as a Markdown table in a .md file, making it super simple to copy/paste the entire piece of text into my documentation in VS Code.

cls$subs = Get-AzSubscription$outString = "| Zone Name | Subscription Name | Resource Group Name | Linked Virtual Network |"Write-Host $outString$outString | Out-File "dnsLinks.md"$outString = "| --------- | ----------------- | ------------------- | ---------------------- |"Write-Host $outString$outString | Out-File "dnsLinks.md" -Appendforeach ($sub in $subs){    try    {        $context = Set-AzContext -subscription $sub.id           $zones = Get-AzPrivateDnsZone        foreach ($zone in $zones)        {            if ($sub.Name -eq "connectivity" -or $sub.Name -eq "connectivity-canary")    {        break    }            try            {                $links = Get-AzPrivateDnsVirtualNetworkLink -ResourceGroupName $zone.ResourceGroupName -ZoneName $zone.Name                       foreach ($link in $links)                {                    try                    {                        $vnetName = ($link.VirtualNetworkId.Split("/")) | Select-Object -Last 1                        $outString  = "| " + $zone.name + " | " + $context.Subscription.Name + " | " + $zone.ResourceGroupName + " | " + $vnetName + " |"                        Write-Host $outString                        $outString | Out-File "dnsLinks.md" -Append                    }                    catch {}                }             }             catch {}        }      }    catch {}}

It probably wouldn’t take a whole lot more work to add any DNS records if you needed that information too.

The post Script – Document All Azure Private DNS Zones first appeared on Aidan Finn, IT Pro.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Azure PowerShell 私有 DNS 文档管理 自动化
相关文章