PowerShell methods for controlling Windows DNS services in Scripts _powershell

Source: Internet
Author: User
Tags mx record

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.