The New-AzDnsRecordSet cmdlet creates a new Domain Name System (DNS) record set with the specified name and type in the specified zone.
A RecordSet object is a set of DNS records with the same name and type.
Note that the name is relative to the zone and not the fully qualified name.
The DnsRecords parameter specifies the records in the record set.
This parameter takes an array of DNS records, constructed using New-AzDnsRecordConfig.
You can use the pipeline operator to pass a DnsZone object to this cmdlet, or you can pass a DnsZone object as the Zone parameter, or alternatively you can specify the zone by name.
You can use the Confirm parameter and $ConfirmPreference Windows PowerShell variable to control whether the cmdlet prompts you for confirmation.
If a matching RecordSet already exists (same name and record type), you must specify the Overwrite parameter, otherwise the cmdlet will not create a new RecordSet .
Examples
Example 1: Create a RecordSet of type A
$Records = @()
$Records += New-AzDnsRecordConfig -IPv4Address 1.2.3.4
$RecordSet = New-AzDnsRecordSet -Name "www" -RecordType A -ResourceGroupName "MyResourceGroup" -TTL 3600 -ZoneName "myzone.com" -DnsRecords $Records
# When creating a RecordSet containing a single record, the above sequence can also be condensed into a single line:
$RecordSet = New-AzDnsRecordSet -Name "www" -RecordType A -ResourceGroupName "MyResourceGroup" -TTL 3600 -ZoneName "myzone.com" -DnsRecords (New-AzDnsRecordConfig -IPv4Address 1.2.3.4)
# To create a record set containing multiple records, use New-AzDnsRecordConfig to add each record to the $Records array,
# then call New-AzDnsRecordSet, as follows:
$Records = @()
$Records += New-AzDnsRecordConfig -IPv4Address 1.2.3.4
$Records += New-AzDnsRecordConfig -IPv4Address 5.6.7.8
$RecordSet = New-AzDnsRecordSet -Name "www" -RecordType A -ResourceGroupName "MyResourceGroup" -TTL 3600 -ZoneName "myzone.com" -DnsRecords $Records
This example creates a RecordSet named www in the zone myzone.com.
The record set is of type A and has a TTL of 1 hour (3600 seconds).
It contains a single DNS record.
This example creates a RecordSet named www in the zone myzone.com.
The record set is of type AAAA and has a TTL of 1 hour (3600 seconds).
It contains a single DNS record.
To create a RecordSet using only one line of pn_PowerShell_short, or to create a record set with multiple records, see Example 1.
This example creates a RecordSet named www in the zone myzone.com.
The record set is of type CNAME and has a TTL of 1 hour (3600 seconds).
It contains a single DNS record.
To create a RecordSet using only one line of pn_PowerShell_short, or to create a record set with multiple records, see Example 1.
This command creates a RecordSet named www in the zone myzone.com.
The record set is of type MX and has a TTL of 1 hour (3600 seconds).
It contains a single DNS record.
To create a RecordSet using only one line of pn_PowerShell_short, or to create a record set with multiple records, see Example 1.
This command creates a RecordSet named ns1 in the zone myzone.com.
The record set is of type NS and has a TTL of 1 hour (3600 seconds).
It contains a single DNS record.
To create a RecordSet using only one line of pn_PowerShell_short, or to create a record set with multiple records, see Example 1.
This command creates a RecordSet named 4 in the zone 3.2.1.in-addr.arpa.
The record set is of type PTR and has a TTL of 1 hour (3600 seconds).
It contains a single DNS record.
To create a RecordSet using only one line of pn_PowerShell_short, or to create a record set with multiple records, see Example 1.
This command creates a RecordSet named _sip._tcp in the zone myzone.com.
The record set is of type SRV and has a TTL of 1 hour (3600 seconds).
It contains a single DNS record, pointing to the IP address 2001.2.3.4.
The service (sip) and the protocol (tcp) are specified as part of the record set name, not as part of the record data.
To create a RecordSet using only one line of pn_PowerShell_short, or to create a record set with multiple records, see Example 1.
This command creates a RecordSet named text in the zone myzone.com.
The record set is of type TXT and has a TTL of 1 hour (3600 seconds).
It contains a single DNS record.
To create a RecordSet using only one line of pn_PowerShell_short, or to create a record set with multiple records, see Example 1.
This command creates a RecordSet at the apex (or root) of the zone myzone.com.
To do this, the record set name is specified as "@" (including the double-quotes).
You cannot create CNAME records at the apex of a zone.
This is a constraint of the DNS standards; it is not a limitation of Azure DNS.
To create a RecordSet using only one line of pn_PowerShell_short, or to create a record set with multiple records, see Example 1.
This command creates a RecordSet named * in the zone myzone.com.
This is a wildcard record set.
To create a RecordSet using only one line of pn_PowerShell_short, or to create a record set with multiple records, see Example 1.
This command creates a RecordSet named www in the zone myzone.com.
The record set is of type A and has a TTL of 1 hour (3600 seconds).
This is an empty record set, which acts as a placeholder to which you can later add records.
Example 12: Create a record set and suppress all confirmation
This command creates a RecordSet.
The Overwrite parameter ensures that this record set overwrites any pre-existing record set with the same name and type (existing records in that record set are lost).
The Confirm parameter with a value of $False suppresses the confirmation prompt.
Parameters
-Confirm
Prompts you for confirmation before running the cmdlet.
Specifies the array of DNS records to include in the record set.
You can use the New-AzDnsRecordConfig cmdlet to create DNS record objects.
See the examples for more information.
Specifies an array of metadata to associate with the RecordSet.
Metadata is specified using name-value pairs that are represented as hash tables, for example @{"dept"="shopping";"env"="production"}.
Specifies the resource group that contains the DNS zone.
You must also specify the ZoneName parameter to specify the zone name.
Alternatively, you can specify the zone and resource group by passing in a DNS Zone object using the Zone parameter.
Specifies the name of the zone in which to create the RecordSet.
You must also specify the resource group containing the zone using the ResourceGroupName parameter.
Alternatively, you can specify the zone and resource group by passing in a DNS Zone object using the Zone parameter.
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable,
-ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see
about_CommonParameters.
You can use the Confirm parameter to control whether this cmdlet prompts you for confirmation.
By default, the cmdlet prompts you for confirmation if the $ConfirmPreference Windows PowerShell variable has a value of Medium or lower.
If you specify Confirm or Confirm:$True, this cmdlet prompts you for confirmation before it runs.
If you specify Confirm:$False, the cmdlet does not prompt you for confirmation.
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.