通过shell枚举Windows DNS服务器区域属性
发布时间:2020-12-15 18:31:57 所属栏目:安全 来源:网络整理
导读:我想使用命令行工具列出(主)区域配置的辅助服务器(如果有). Dnscmd接近: dnscmd server /ZoneResetSecondaries:[list of secondaries] 但是,我不想破坏任何当前设置,我只想查看它们. PowerShell(甚至在Server 2012上)似乎没有帮助. 谢谢. 你是最正确的,你可
|
我想使用命令行工具列出(主)区域配置的辅助服务器(如果有).
Dnscmd接近: dnscmd server /ZoneResetSecondaries:[list of secondaries] 但是,我不想破坏任何当前设置,我只想查看它们. PowerShell(甚至在Server 2012上)似乎没有帮助. 谢谢.
你是最正确的,你可以:
>枚举区域并查找“主要”区域 我以前written about parsing function Get-DNSZones
{
param(
[String]$ComputerName = "."
)
$enumZonesExpression = "dnscmd $ComputerName /enumzones"
$dnscmdOut = Invoke-Expression $enumZonesExpression
if(-not($dnscmdOut[$dnscmdOut.Count - 2] -match "Command completed successfully."))
{
Write-Error "Failed to enumerate zones"
return $false
}
else
{
# The output header can be found on the fifth line:
$zoneHeader = $dnscmdOut[4]
# Let's define the the index,or starting point,of each attribute:
$d1 = $zoneHeader.IndexOf("Zone name")
$d2 = $zoneHeader.IndexOf("Type")
$d3 = $zoneHeader.IndexOf("Storage")
$d4 = $zoneHeader.IndexOf("Properties")
# Finally,let's put all the rows in a new array:
$zoneList = $dnscmdOut[6..($dnscmdOut.Count - 5)]
# This will store the zone objects when we are done:
$zones = @()
# Let's go through all the rows and extrapolate the information we need:
foreach($zoneString in $zoneList)
{
$zoneInfo = @{
Name = $zoneString.SubString($d1,$d2-$d1).Trim();
ZoneType = $zoneString.SubString($d2,$d3-$d2).Trim();
Storage = $zoneString.SubString($d3,$d4-$d3).Trim();
Properties = @($zoneString.SubString($d4).Trim() -split " ")
}
$zoneObject = New-Object PSObject -Property $zoneInfo
$zones += $zoneObject
}
return $zones
}
}
现在,您可以列出所有主要区域: Get-DNSZones|Where-Object {$_.ZoneType -eq 'Primary'}
然后,您可以使用区域阵列自动查找所有主要区域: $PrimaryZones = Get-DNSZones|Where-Object {$_.ZoneType -eq 'Primary'}
$PrimaryZones |% {$out = iex "dnscmd . /ZoneInfo $($_.ZoneName) |find `"Zone Secondaries`" "; "$($_.ZoneName) = $out"}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
