Solved

need a powershell script to modify a set of DNS records - bulk

Posted on 2013-10-24
8
1,298 Views
Last Modified: 2013-10-29
can someone provide a script that we can run to update [modify] the IP address on a set of records.

sample would be:

record:                                 New IP
www.domaina.com            192.168.10.1
www.domainb.com            192.168.10.1
www.domainc.com             192.168.10.1
www.domaind.com             192.168.10.1

thanks in advance.

S.
0
Comment
Question by:siber1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 39597582
There are no native Powershell cmdlets to accomplish what you are doing for server 2008. If you are using Server 2012 you can do this natively.

For server 2008 there has been a script to accomplish this using dnscmd to modify DNS records.

PS Script Download - http://gallery.technet.microsoft.com/scriptcenter/Update-DNS-records-with-da10910d

You will need to add your list of computers to the script via CSV file.

You can use the below script to get a list of computers from the DisabledComputers OU and then export them to a csv file. From there you put the file path into the PS script found at the download link...

Get-ADComputer -Filter * -SearchBase "OU=DisabledComputers,DC=domain,DC=com" | select DNSHostName | Export-csv "c:\computers.csv"

PAQ (still open) - http://www.experts-exchange.com/Software/Server_Software/File_Servers/Active_Directory/Q_28275106.html

Will.
0
 
LVL 29

Expert Comment

by:becraig
ID: 39597586
Are you hoping to an additional record or remove the old one and create a new record ?

Here is an already scripted solution using dnscmd.
http://gallery.technet.microsoft.com/scriptcenter/Update-DNS-records-with-da10910d

The concept is simple you feed in values such as your dns server, zone name and an input file with the records you want to update eg. Record, IP
# Environment Setup 
$DNSServer = "YourDNSServer" 
$DNSZone = "YourZoneName" 
$InputFile = "dnsrecords.csv" 
 
# Read the input file which is formatted as name,type,address with a header row 
$records = Import-CSV $InputFile 
 
# Now we loop through the file to delete and re-create records 
# DNSCMD does not have a modify option so we must use /RecordDelete first followed by a /RecordAdd  
 
ForEach ($record in $records) { 
 
    # Capture the record contents as variables 
    $recordName = $record.name 
    $recordType = $record.type 
    $recordAddress = $record.address 
 
    # Build our DNSCMD DELETE command syntax 
    $cmdDelete = "dnscmd $DNSServer /RecordDelete $DNSZone $recordName $recordType /f" 
 
    # Build our DNSCMD ADD command syntax 
    $cmdAdd = "dnscmd $DNSServer /RecordAdd $DNSZone $recordName $recordType $recordAddress" 
 
    # Now we execute the command 
    Write-Host "Running the following command: $cmdDelete" 
    Invoke-Expression $cmdDelete 
 
    Write-Host "Running the following command: $cmdAdd" 
    Invoke-Expression $cmdAdd 
}

Open in new window



You can visit the link above for a detailed explanation on usage.
0
 

Author Comment

by:siber1
ID: 39597680
becraig, this appears to be specific to a single zone. in my case each line item is a different zone in the csv.  thx
0
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 29

Expert Comment

by:becraig
ID: 39597709
You can simply modify the zone input:
is the zone in the same csv as the record and IP ?
0
 

Author Comment

by:siber1
ID: 39597720
but your script asks for the zone in the environmental setup at the top
0
 
LVL 40

Expert Comment

by:footech
ID: 39597723
0
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 39597749
Let's assume the zone is in the same csv as the other fields:
# Environment Setup 
$DNSServer = "YourDNSServer" 
$InputFile = "dnsrecords.csv" 
 
# Read the input file which is formatted as name,type,address with a header row 
$records = Import-CSV $InputFile 
 
# Now we loop through the file to delete and re-create records 
# DNSCMD does not have a modify option so we must use /RecordDelete first followed by a /RecordAdd  
 
ForEach ($record in $records) { 
 
    # Capture the record contents as variables 
    $recordName = $record.name 
    $DNSZone =  $record.zone
    $recordType = $record.type 
    $recordAddress = $record.address 
 
    # Build our DNSCMD DELETE command syntax 
    $cmdDelete = "dnscmd $DNSServer /RecordDelete $DNSZone $recordName $recordType /f" 
 
    # Build our DNSCMD ADD command syntax 
    $cmdAdd = "dnscmd $DNSServer /RecordAdd $DNSZone $recordName $recordType $recordAddress" 
 
    # Now we execute the command 
    Write-Host "Running the following command: $cmdDelete" 
    Invoke-Expression $cmdDelete 
 
    Write-Host "Running the following command: $cmdAdd" 
    Invoke-Expression $cmdAdd 
}

Open in new window


Updated above to call the zone from your csv file (using the assumption the field is zone it is set above to  $DNSZone =  $record.zone
0
 

Author Closing Comment

by:siber1
ID: 39610464
thanks, sorry for the delay, was out of town. that works great.

S.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question