Virtualization, Cloud, Infrastructure and all that stuff in-between

My ramblings on the stuff that holds it all together

POSH1Liner – Add sequential DNS A records

When setting up a new environment you often need to create a bunch of sequential DNS A records, with reverse look up PTR records.

For example, I do this in my home lab – this 1-liner creates hosts 1..16.

You can adjust the server naming convention by editing the $name variable to suit and editing the -ZoneName parameter to match your environment.

Likewise, you can adjust to fit your IP addressing schema by editing the $ip variable/

To start at a different number (mine start from 1), adjust the $num = 1 statement.

 
for ($num =1; $num -le 16; $num++) { $name="L1-slot" + $num ; $ip = "172.16.10." +$num ; Add-DnsServerResourceRecordA -Name $name -ZoneName "theBORG.int" -AllowUpdateAny -IPv4Address $ip -CreatePTR ; }

 

In my example I’m running this on my lab Windows DC/DNS server (home lab, not production!), if you’re doing it from a different server you can add a -ComputerName “yourDNSserver.local” parameter to point it at your DNS server.

Note the use of the semi-colon ; to pass multiple PowerShell commands on a single line making it easier to cut & paste this command.

If you’re doing this ‘for real’ outside your own lab you can also use the -WhatIf parameter to see what would happen.

Blogged here for the next time I need to do this!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: