虽然我对PowerShell v3相当陌生,但是我可以用它做一些事情,但是有一点我不明白,就是如何将所有在DNSpipe理器(Server 2008 R2)中列出的主机挂起来。 我不需要设置或删除任何东西,只要把它列入一个文本文件查询列表。 令人惊讶的是我没有find办法做到这一点。 任何人都知道如何做到这一点,请吗?
我之前使用过DNSShell。 http://dnsshell.codeplex.com/ 。 要获得区域中的所有Alogging,可以这样做:
Get-DnsRecord -RecordType A -ZoneName FQDN -Server ServerName
为了得到这个文本文件:
Get-DnsRecord -RecordType A -ZoneName FQDN -Server ServerName | % {Add-Content -Value $_ -Path filename.txt}
我还没有看到提到的另一种方法:
Get-WmiObject -Namespace Root\MicrosoftDNS -Query "SELECT * FROM MicrosoftDNS_AType WHERE ContainerName='domain.com'"
当WMI出于某种原因无法下载DnsShell时,或者如果您使用的是旧版本的没有Cmdlet的旧版本的Powershell,或者如果您的目标是早期版本的Windows Server 。
Windows Server 2012,Powershell v3中提供的DnsServer模块具有以下对您可能有用的命令:
Get-DnsServerZone Get-DnsServerResourceRecord
第一个会让你所有的区域第二个会得到你传递给它的任何区域的logging
它们基本上等同于DNSCMD /EnumZones
和/EnumRecords
。
所以…你可以写这样的东西来获得所有区域的所有logging:
$Zones = @(Get-DnsServerZone) ForEach ($Zone in $Zones) { Write-Host "`n$Zone.ZoneName" -ForegroundColor "Yellow" $Zone | Get-DnsServerResourceRecord }
另外,我很确定server 2012现在为每个区域保留一个实际的区域文件? 所以你应该有一个文件的所有区域的副本。
如果您正在使用2008 R2,那么您可以使用此脚本将我的所有区域备份到文件中:
$zones = @( ` dnscmd /enumzones | ` select-string -pattern "\b(?i)((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[az]{2,63}\b" | %{$_.Matches} | %{$_.Value}; ); ForEach ($domain in $zones) { $backup = "dnscmd . /zoneExport $domain $domain"; Invoke-Expression $backup | Out-Null Write-Host "Backing up $domain" -ForegroundColor "White" }; ForEach ($item in (gci C:\Windows\System32\dns)) { Write-Host "Renaming $item" -ForegroundColor "White" Rename-item $item.fullname ([string]$item + ".dns") } Write-Host "Back up complete." -ForegroundColor "Cyan" cmd /c pause | out-null