forked from limeman38/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addDNSEntries.ps1
89 lines (70 loc) · 2.86 KB
/
addDNSEntries.ps1
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
################################################################
##
## removeDNSEntires.ps1
## Created By : Nick Clark
## Owner : NickClark.biz
## Date : March 2018
##
## Copyright © 2016 NickClark.biz
## This software is proprietarily created and maintained by NickClark.biz for its sole use.
## You may NOT redistribute copies of this code.
## There is NO WARRANTY, to the extent permitted by law.
##
################################################################
function addDNSEntries
{
#Get input from user
#$dnsServer = Read-Host 'What DNS server would you like to use?'
#$zoneName = Read-Host 'What DNS zone are you adding to'
Write-Host "Please select your CSV for input!." -ForegroundColor red -BackgroundColor white
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
Multiselect = $false # Multiple files can be chosen
Filter = "csv files (*.csv)|*.csv|All files (*.*)|*.*"# Text file filter
} #End Add-Type for form
[void]$FileBrowser.ShowDialog()
$file = $FileBrowser.FileName;
If($FileBrowser.FileNames -like "*\*") {
#Do something
$FileBrowser.FileName #Lists selected files (optional)
}
else
{
Write-Host "Canceled by user"
} #end else
$fileInput = Import-CSV $file
foreach ($fileLine in $fileInput)
{
#Add DNS Record A
Add-DnsServerResourceRecordA -Name $($fileLine.HOSTNAME) -ComputerName $($fileLine.DNSSERVER) -ZoneName $($fileLine.DOMAIN) -AllowUpdateAny -IPv4Address $($fileLine.IP) -TimeToLive 01:00:00 -Confirm -CreatePtr
#ADD PTR Record
add-DnsServerResourceRecordPtr -Name $($fileLine.HOSTNAME) -ComputerName $($fileLine.DNSSERVER) -ZoneName $($fileLine.ZONE) -AllowUpdateAny -TimeToLive 01:00:00 -AgeRecord -PtrDomainName $($fileLine.DOMAIN)
get-DnsServerResourceRecord -ZoneName $($fileLine.DOMAIN) -ComputerName $($fileLine.DNSSERVER) -Name $($fileLine.HOSTNAME)
} #end for loop
} #End Function
function removeDNSEntries
{
#Get input from user
$dnsServer = Read-Host 'What DNS server would you like to use?'
$zoneName = Read-Host 'What DNS zone are you removing from'
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
Multiselect = $false # Multiple files can be chosen
Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"# Text file filter
} #End Add-Type for form
[void]$FileBrowser.ShowDialog()
$file = $FileBrowser.FileName;
If($FileBrowser.FileNames -like "*\*") {
#Do something
$FileBrowser.FileName #Lists selected files (optional)
}
else
{
Write-Host "Canceled by user"
} #end else
$fileInput = Get-Content $file
foreach ($line in $fileInput)
{
Remove-DnsServerResourceRecord -ComputerName $dnsServer -ZoneName $zoneName -RRType "A" -Name $line
} #end for loop
} #end function