PowerShell can easily operate WMI, and the DNS service provides good WMI support, so PowerShell can manipulate the Windows DNS service by manipulating WMI.
1. Get the DNS object.
Copy Code code as follows:
ps> $mydns = [WMIClass] "Root\microsoftdns:microsoftdns_resourcerecord"
2, the creation of analytic records, using the Createinstancefromtextrepresentation method.
Copy Code code as follows:
Ps> $mydns. Createinstancefromtextrepresentation ("Server name", "Domain Name", "Www.jb51.net in A 127.0.0.1")
Description
1 The prototype of the Createinstancefromtextrepresentation method is as follows:
Copy Code code as follows:
System.Management.ManagementBaseObject createinstancefromtextrepresentation (System.String dnsservername, System.String containername, System.String textrepresentation)
2 The server name, if it is native, can be set to null.
3 domain name is jb51.net such.
4 www.jb51 is a subdomain; in is the network type (the TCP/IP protocol is generally in, the small part has not seen anything else); a indicates a record, it resolves to an IP address (followed by the 127.0.0.1); If the MX representation is a mail record, it resolves to the address of a mail server;
3, PowerShell Use the file batch add DNS resolution
Copy Code code as follows:
$dnsServerName = ""
$containerName = "Jb51.net"
ps> $mydns = [WMIClass] "Root\microsoftdns:microsoftdns_resourcerecord"
ps> get-content DnsListFile.txt | Foreach-object {$mydns. Createinstancefromtextrepresentation ($dnsServerName, $containerName, $_)}
Description: The format of the DnsListFile.txt file is as follows:
Copy Code code as follows:
Www.jb51.net in A 127.0.0.1
Mail.jb51.net in A 127.0.0.2
Jb51.net in MX mail.jb51.net
This example is done by doing a www.jb51.net of a record parsing to 127.0 0.1, then doing a mail.jb51.net of a records parsing to 127.0.0.2, and finally doing a jb51.net MX record to mail.jb51.net this host.
Small series of reference to some of the online cattle of the article, refined a bit, hoping to help everyone.