-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDNSCache.ps1
93 lines (60 loc) · 2.29 KB
/
DNSCache.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
90
91
92
93
### Snippets for working with DNS Caching
################## Get all Domain Controllers
$dc = Get-ADDomainController -Filter * | Select name
$dc.Count
# Get Cache Settings
$results = foreach ($d in $dc){
$cacheSettings = Get-DnsServerCache -ComputerName $d.name |
Select @{Name='Server'; Expression={$d.name}}, MaxTTL, ZoneName
}
################# Examine Cache Contents
$results = foreach ($d in $dc){
$cache = Show-DnsServerCache
$cache | Where-Object {$_.TimeToLive -gt "23:00:00"} | Sort-Object -Property TimeToLive -Descending
$cache | where {$_.hostname -like "*kleinwortbensons*"}
$cache | Where-Object {$_.RecordData.IPv4Address -like "193.*"}
}
break
####################### Drop Cache Entirely EMEA Only ################
Start-Transcript -Path $env:TEMP\DNSCacheChange2.log
$emea = @(
'DC-01','DC-02','DC-03','DC-04')
Foreach ($dc in $emea){
Set-DnsServerCache -MaxTtl 0 -ComputerName $dc
}
Foreach ($dc in $emea){
Get-DnsServerCache -ComputerName $dc
}
Clear-DnsServerCache -ComputerName $dc -force
Resolve-DnsName www.google.com -Server $dc
Show-DnsServerCache -ComputerName $dc | select -First 100
Get-DnsServerCache -ComputerName $dc
################## Drop Cache Time
Start-Transcript -Path $env:TEMP\DNSCacheChange.log
$timespan = New-TimeSpan -Minutes 15
# Record pre-change values
$dc = Get-ADDomainController -Filter * | where {$_.name -notlike "NDH*"}
$dc = $dc | where {$_.name -notlike "CHD*"}
foreach ($d in $dc){
Get-DnsServerCache -ComputerName $d.name -WarningAction SilentlyContinue |
Select @{Name='Server'; Expression={$d.name}}, @{Name='MaxTTL'; Expression={($_.maxTTL)}}
}
# Make the change
foreach ($d in $dc){
Set-DnsServerCache -MaxTtl $timespan -ComputerName $d.name
}
# Validate change
foreach ($d in $dc){
Get-DnsServerCache -ComputerName $d.name -WarningAction SilentlyContinue |
Select @{Name='Server'; Expression={$d.name}}, @{Name='MaxTTL'; Expression={($_.maxTTL)}}
}
# Clear the cache
foreach ($d in $dc){
Clear-DnsServerCache -ComputerName $d.name
}
# Let the cache repopulate for a bit and example the TTL values
foreach ($d in $dc){
$cacheSample = Show-DnsServerCache -ComputerName $d.name | select -First 20
$cacheSample | Sort-Object TimeToLive -Descending
}
Stop-Transcript