Prior to creating a new Web Application in our SharePoint 2010 environment, I would like to add a host A record to DNS so that the URL we assign to our web application is directed to the appropriate IP Address. I will create a new address record for ‘lab.ps4sp.com’ and associate it to 192.168.100.86.
In this example, I have the following setup:
Domain Name: PS4SP.com
Domain Controller Name: PS-DC
SharePoint Server Name: PS-SPS
SharePoint Server IP: 192.168.100.86
In figure 1 below, you should be able to confirm these details.
In order to accomplish this task in PowerShell, we will use MicrosoftDNS_AType, which is a subclass of MicrosoftDNS_ResourceRecord that represents a host Address (A) record. We then use the CreateInstanceFromPropertyData to create the address record.
Fully Qualified Domain Name (FQDN) or IP address of the DNS Server that contains this RR.
Name of the Container for the Zone, Cache, or RootHints instance which contains this RR.
Owner FQDN for the RR.
Note Do not use the owner NetBIOS name.
RecordClass [in, optional]
Class of the RR. Default value is 1. The following values are valid.
TTL [in, optional]
Time, in seconds, that the RR can be cached by a DNS resolver.
String representing the IP address of the host.
Reference to the new object.
# Set the FQDN of the domain controller
$dnsServer = “ps-dc.ps4sp.com”
# Set the dns zone name of where to place the host A record
$dnsZone = “ps4sp.com”
# Set the name of the Host A
$hostA = “lab.ps4sp.com”
# Set the class: 1 = Internet, 2 = CSNet, 3 = CHAOS, 4 = Hesiod
$class = 1
# Set the TTL, time that the RR can be cached
$ttl = 3600
# Set the IP Address of the destination
$IPAddress = “192.168.100.86”
# Assign the MicrosoftDNS_AType
$dnsAType = [wmiclass]“\$dnsServerrootMicrosoftDNS:MicrosoftDNS_AType”
# Use CreateInstanceFromPropertyData to create the host A record
$dnsAType.CreateInstanceFromPropertyData($DNSserver, $dnsZone, $hostA, $class, $ttl, $IPAddress)
Figure 2 shows how the script looks inside PowerShell ISE. Figure 3 show the results of the command inside the DNS Manager.