Imagine you have to create hundreds or thousands of DNS records. Do you want to do that one by one? Surely not. I will show you an example how to create Beamer01 – Beamer100 and assign an IP address at the same time. Let’s jump in.
The Objective
Let’s say we want to create A Records Beamer01 – Beamer100 with the IP-Addresses 192.168.1.1 – 192.168.1.99.

The Code
Here is the example code you can build on. The script creates Beamer01 – Beamer99 with the corresponding IP addresses.
$ip = 1..99
foreach ($i in $ip) {
If ($i -lt 10) {
Add-DnsServerResourceRecord `
-ZoneName 'test.local' `
-Name Beamer0$i -IPv4Address 192.168.1.$i -A -Verbose
}
else
{
Add-DnsServerResourceRecord `
-ZoneName 'test.local' `
-Name Beamer$i -IPv4Address 192.168.1.$i -A -Verbose
}
}
I hope this was helpful.
Categories: PowerShell, Windows Server