PowerShell for DNS Part 4

Sign up to access this lesson

Click here to sign up and get access to this lesson!

Saving Progress...

In this lecture I’m going to show you how to create multiple A-Host records. With these commands you can create 5 or a hundred A-host records in seconds with PowerShell.  

  • In case you forgot an A record associates a domain name to the matching IP address of that computer.

We will be working from the Domain Controller IPDC01.  

  • I encourage you to follow along as all this information has been included in the lesson that came with the lecture.

So, the first thing that were going to do is were going to click on windows explorer and I want to show you folder that I created, called scripts.

So, within that folder I created a CSV file called computers.csv.  

  • So, what’s a CSV file? It’s’ a comma separated value file)

Now within this file, I have two column headers, one is Hostname separated by a coma, and the other is IPAddress. Underneath my Hostname are all my hosts, IPSW05 through IPSW14. And all the associated IP addresses.  

  • These hostnames are for testing purposes if you were creating these for a production network you would need to change the IPAddress to correspond to your IP network and change the hostnames to whatever will work best in your environment.  

HostName,IPAddress

IPSW05,10.0.2.30

IPSW06,10.0.2.31

IPSW07,10.0.2.32

IPSW08,10.0.2.33

IPSW09,10.0.2.34

IPSW10,10.0.2.35

IPSW11,10.0.2.36

IPSW12,10.0.2.37

IPSW13,10.0.2.38

IPSW14,10.0.2.39

  • Now how do you create a CSV file? You click file, save as. Click save as type, then click All Files. For a filename type computers.csv. Normally you would click save, but I will click cancel.

Now let’s go ahead and open up PowerShell in Administrative mode.

Here’s our script

  • Import-CSV -Path C:\Scripts\computers.csv | %{ Add-DNSServerResourceRecordA ZoneName instructorpaul.com -Name $_."Hostname" -IPv4Address $_."IPAddress" }
  • What we have here is two commands. Command #1 is Import-CSV and Command #2 is Add-DNSServerResourceRecordA.  
  • So what command 1 is telling PowerShell is to get ready to import a CSV file. The parameter -Path tells PowerShell to take a look at c:\scripts\computers.csv  
  • The pipe Operator tells PowerShell to take the output of command #1 and pass it across the pipeline to the input of Command # 2.
  • Now if you recall from our csv file, we had two column headers, one called Hostname and the other IPAddress. And underneath our hostname was all our host names all the associated IP addresses.
  • So, if you take a look at this %. What that % is. It’s an alias for the foreach-object function. So, what this really means is that ForEach-Object, and a associated IP address. PowerShell is going to create a associated DNS server resource record. And create that record in the zone file name of instructorpaul.com.  

So, let’s go run the command. Then I’ll explain further. It looks like our script ran.

Ok, let’s go ahead and explain a little bit more what this script actually did.

  • Here’s our C: drive and here is our Scripts folder. Here our computers.csv file. Here is command 1, Import-CSV.  
  • The pipeline tells PowerShell to take the output from command #1 and push it across the pipeline to Command # 2.  
  • Here’s our HostName and IPAddress. And underneath our hostname are all our hosts with the associated IPAddress.  
  • There’s our % and as we said before it’s an alias for the foreach-object function. What that means is that for each object or should I say hostname, PowerShell is going to add a DNS resource record to the zone name instructorpaul.com.

Ok let’s go ahead and open up DNS manager. And as you can see we have our new resource records IPSW05 down to IPSW14 and all the associated resource records. So that script did work.

Sign up to access the rest of this lesson

You must either log in or sign up to access this lesson.

Saving Progress...

5 1 vote
Lesson Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments

Installing and Configuring Domain Name System (DNS)

0%

0/1 Lessons

Course Introduction

• 10min

0 / 2 lessons complete

DNS Basics

• 1hr 16min

0 / 8 lessons complete

DNS Resource Records

• 46min

0 / 5 lessons complete

DNS Zones

• 4hr 11min

0 / 12 lessons complete

DNS Delegation

• 50min

0 / 4 lessons complete

DNS Security Techniques

• 36min

0 / 5 lessons complete

Advanced DNS Topics

• 22min

0 / 5 lessons complete

DNS Security (DNSSEC)

• 1hr 16min

0 / 6 lessons complete

DNS Policies

• 55min

0 / 6 lessons complete

PowerShell for DNS

• 1hr 27min

0 / 6 lessons complete

Troubleshooting DNS Issues - Troubleshooting Tools

• 1hr 39min

0 / 8 lessons complete