-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_dns.ps1
More file actions
51 lines (48 loc) · 1.5 KB
/
set_dns.ps1
File metadata and controls
51 lines (48 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<#
.Synopsis
Adds the given DNS A records to the desired DNS zone
.DESCRIPTION
This script is intended to be run by a machine deployed within glab and is
primarily used to bootstrap the glab domain with the necessary DNS records.
.EXAMPLE
.\set_dns.ps1 -ComputerName DC00 -ZoneName my.domain -RecordsFile .\dns\records.psd1
.NOTES
Name: set_dns.ps1
Author: Joshua Gilman (@jmgilman)
#>
# Parameters
param(
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
Position = 1
)]
[string] $ComputerName,
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
Position = 2
)]
[string] $ZoneName,
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
Position = 3
)]
[string] $RecordsFile
)
# Don't let the script continue with errors
$ErrorActionPreference = 'Stop'
# Update A records
$records = Import-PowerShellDataFile $RecordsFile
$all_res = Get-DnsServerResourceRecord -ComputerName $ComputerName -ZoneName $ZoneName
foreach ($record in $Records.GetEnumerator()) {
$res = $all_res | Where-Object HostName -EQ $record.Name
if (!$res) {
Write-Verbose "Adding record for $($record.Name)"
Add-DnsServerResourceRecordA -ComputerName $ComputerName -ZoneName $ZoneName -Name $record.Name -IPv4Address $record.Value
}
}