Board logo

标题: [转载教程] PowerShell实现DNS添加、修改、查询、删除A记录 [打印本页]

作者: DAIC    时间: 2014-10-23 11:11     标题: PowerShell实现DNS添加、修改、查询、删除A记录

#查询DNS可用类
  1. Get-WmiObject -Namespace root\MicrosoftDNS -List
复制代码
#查询所有资源记录
  1. $mydns = [WMIClass]"ROOT\MicrosoftDNS:MicrosoftDNS_ResourceRecord"
  2. $mydns = [WMIClass]"\\$Server\ROOT\MicrosoftDNS:MicrosoftDNS_ResourceRecord"
复制代码
#查询已有区域
  1. gwmi -Namespace root\microsoftdns -Class MicrosoftDNS_zone |select ContainerName
复制代码
#查询 ddv.com区域下的所有A记录
  1. Get-WmiObject -Namespace root\MicrosoftDNS -class microsoftdns_atype | ? {$_.ContainerName -eq "ddv.com"} |Select TextRepresentation
复制代码
#查询单条A记录
#查询 bb.ddv.com 的A记录
  1. $ARecord = Get-WmiObject -Namespace root\MicrosoftDNS -class MicrosoftDNS_ResourceRecord -filter "containername='ddv.com' AND OwnerName='bb.ddv.com'"
复制代码
#查询 bb.ddv.com 的A记录
  1. $ARecord = Get-WmiObject -Namespace root\MicrosoftDNS -class microsoftdns_atype | ? {$_.OwnerName -eq "bb.ddv.com"}
复制代码
#修改A记录
#修改A记录 bb.ddv.com 的IP指向为172.0.0.23
  1. $ARecord = Get-WmiObject -Namespace root\MicrosoftDNS -class microsoftdns_atype | ? {$_.OwnerName -eq "bb.ddv.com"}
  2. $ARecord.Modify($ARecord.TTL,"127.0.0.223")
复制代码
#删除A记录
#删除A记录 bb.ddv.com
  1. $ARecord = Get-WmiObject -Namespace root\MicrosoftDNS -class microsoftdns_atype | ? {$_.OwnerName -eq "bb.ddv.com"}
  2. $ARecord.delete()
复制代码
#添加A记录
#添加单条A记录 bb.ddv.com IN A 127.0.0.3
  1. $dnsServerName=""
  2. $containerName="ddv.com"
  3. $dns = [WMIClass]"ROOT\MicrosoftDNS:MicrosoftDNS_ResourceRecord"
  4. $dns.CreateInstanceFromTextRepresentation($dnsServerName, $containerName, "bb.ddv.com IN A 127.0.0.3")
复制代码
#批量添加A记录
  1. $dnsServerName=""
  2. $containerName="ddv.com"
  3. $dns = [WMIClass]"ROOT\MicrosoftDNS:MicrosoftDNS_ResourceRecord"
  4. Get-Content D:\dnsListFile.txt | Foreach-Object {$dns.CreateInstanceFromTextRepresentation($dnsServerName, $containerName, $_)}
复制代码
dnsListFile.txt内容如下:

aaa.ddv.com IN A 127.0.0.1
bb.ddv.com IN A 127.0.0.2

#查询转发服务器
  1. gwmi -Namespace "root\MicrosoftDNS" -class "MicrosoftDNS_Server" | Select-Object -ExpandProperty Forwarders
复制代码
From http://www.cnblogs.com/dreamer-fish/p/4022651.html




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2