| | | | | |

Set DNS using Powershell

The purpose of this article is to show case how to add a new A record to a DNS zone using PowerShell.

Here is a quick look at the available Syntax for : Add-DnsServerResourceRecordA

Add-DnsServerResourceRecordA [-AllowUpdateAny] [-CreatePtr] [-Name] <String> [-IPv4Address] <IPAddress[]> [-ComputerName <String>] [-TimeToLive <TimeSpan>] [-ZoneName] <String> [-AgeRecord] [-PassThru] [-ZoneScope <String>] [-VirtualizationInstance <String>] [-CimSession <CimSession[]>] [-ThrottleLimit <Int32>] [-AsJob] [-WhatIf] [-Confirm] [<CommonParameters>]

Now lets look at a quick example:

Add-DnsServerResourceRecordA -Name Nerd01 -ZoneName ThatLazyAdmin.local 
-AllowUpdateAny -IPv4Address 10.10.20.30 -TimeToLive 01:00:00

Let’s add this is a quick small script:

$ErrorActionPreference = 'Continue'
$dnsrecord = Read-Host 'Enter New ARecord Name'
$zonename = Read-Host 'Enter Zone Name'
$ip = Read-Host 'Enter IPv4 Address'
Write-Host -NoNewline "New Record Created:"-ForegroundColor Yellow
Add-DnsServerResourceRecordA -Name $dnsrecord -ZoneName $zonename -AllowUpdateAny 
-IPvAddress $ip -TimeToLive 01:00:00 
Write-Host 'ARecord:'$dnsrecord,'DNS-Zone:'$zonename,'IPv4:'$ip -ForegroundColor Green

 

#ThatLazyAdmin

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *