$prefix = "aidi"
$centerfix = "dayone"
$suffix = "org"
$num = 100;
$ipAddress = "192.168.1.231"
$zoneNames = @("$centerfix.debian.org") # 指定要创建记录的区域
foreach ($zoneName in $zoneNames) {
# 检查区域是否存在,如果不存在则创建
$existingZone = Get-DnsServerZone -Name $zoneName -ErrorAction SilentlyContinue
if (-not $existingZone) {
Add-DnsServerPrimaryZone -Name $zoneName -ZoneFile "$zoneName.dns"
}
for ($i = 1; $i -le $num; $i++) {
$index = if ($i -lt 10) { "0$i" } else { $i }
$domainName = "{0}{1}.{2}.{3}" -f $prefix, $index, $centerfix, $suffix
$recordName = "{0}{1}" -f $prefix, $index
# 检查是否已经存在同名记录
$existingRecord = Get-DnsServerResourceRecord -ZoneName $zoneName -Name $recordName -ErrorAction SilentlyContinue
if (-not $existingRecord) {
# 如果不存在同名记录,则创建新的记录
Add-DnsServerResourceRecordA -ZoneName $zoneName -Name $recordName -IPv4Address $ipAddress
Write-Host "Created A record for $domainName in zone $zoneName"
}
else {
Write-Host "Record $recordName already exists in zone $zoneName, skipping."
}
}
}
windows server ps1脚本创建DNS区域
最新推荐文章于 2024-05-16 23:31:58 发布