标题: [转载教程] PowerShell实现DNS添加、修改、查询、删除A记录 [打印本页]
作者: DAIC 时间: 2014-10-23 11:11 标题: PowerShell实现DNS添加、修改、查询、删除A记录
#查询DNS可用类- Get-WmiObject -Namespace root\MicrosoftDNS -List
复制代码
#查询所有资源记录- $mydns = [WMIClass]"ROOT\MicrosoftDNS:MicrosoftDNS_ResourceRecord"
- $mydns = [WMIClass]"\\$Server\ROOT\MicrosoftDNS:MicrosoftDNS_ResourceRecord"
复制代码
#查询已有区域- gwmi -Namespace root\microsoftdns -Class MicrosoftDNS_zone |select ContainerName
复制代码
#查询 ddv.com区域下的所有A记录- Get-WmiObject -Namespace root\MicrosoftDNS -class microsoftdns_atype | ? {$_.ContainerName -eq "ddv.com"} |Select TextRepresentation
复制代码
#查询单条A记录
#查询 bb.ddv.com 的A记录- $ARecord = Get-WmiObject -Namespace root\MicrosoftDNS -class MicrosoftDNS_ResourceRecord -filter "containername='ddv.com' AND OwnerName='bb.ddv.com'"
复制代码
#查询 bb.ddv.com 的A记录- $ARecord = Get-WmiObject -Namespace root\MicrosoftDNS -class microsoftdns_atype | ? {$_.OwnerName -eq "bb.ddv.com"}
复制代码
#修改A记录
#修改A记录 bb.ddv.com 的IP指向为172.0.0.23- $ARecord = Get-WmiObject -Namespace root\MicrosoftDNS -class microsoftdns_atype | ? {$_.OwnerName -eq "bb.ddv.com"}
- $ARecord.Modify($ARecord.TTL,"127.0.0.223")
复制代码
#删除A记录
#删除A记录 bb.ddv.com- $ARecord = Get-WmiObject -Namespace root\MicrosoftDNS -class microsoftdns_atype | ? {$_.OwnerName -eq "bb.ddv.com"}
- $ARecord.delete()
复制代码
#添加A记录
#添加单条A记录 bb.ddv.com IN A 127.0.0.3- $dnsServerName=""
- $containerName="ddv.com"
- $dns = [WMIClass]"ROOT\MicrosoftDNS:MicrosoftDNS_ResourceRecord"
- $dns.CreateInstanceFromTextRepresentation($dnsServerName, $containerName, "bb.ddv.com IN A 127.0.0.3")
复制代码
#批量添加A记录- $dnsServerName=""
- $containerName="ddv.com"
- $dns = [WMIClass]"ROOT\MicrosoftDNS:MicrosoftDNS_ResourceRecord"
- 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
#查询转发服务器- 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 |