forked from 15below/Ensconce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdnsHelper.ps1
52 lines (44 loc) · 1.43 KB
/
dnsHelper.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
function CheckName ([string]$dnsServer, [string]$domain, [string]$lookupName)
{
$result = dnscmd $dnsServer /EnumRecords $domain $lookupName
$outcome = $False
foreach ($item in $result)
{
if ($item.Contains("3600 CNAME"))
{
$outcome = $True
}
}
$outcome
}
function CreateCName ([string]$dnsServer, [string]$domain, [string]$name, [string]$server)
{
write-host "Creating dns CNAME record for $name.$domain pointing at $server"
$result = dnscmd $dnsServer /recordAdd $domain $name CNAME $server
$outcome = $false
foreach ($item in $result)
{
if ($item.Contains("3600 CNAME") -And $item.Contains("Command completed successfully"))
{
$outcome = $true
}
}
$outcome
}
function CheckHostsEntry ([string]$Address, [string]$FullyQualifiedName)
{
write-host "Checking hosts file for $Address pointing at $FullyQualifiedName"
$checkEntry = "^\s*$Address\s+$FullyQualifiedName\s*$"
$matches = (Get-Content "$env:windir\System32\drivers\etc\hosts") -match $checkEntry
If ($matches.Count -gt 0)
{ $True}
else
{ $False}
}
function AddHostsEntry ([string]$Address, [string]$FullyQualifiedName)
{
write-host "Creating hosts file entry for $Address pointing at $FullyQualifiedName"
$newEntry = "`n$Address`t$FullyQualifiedName"
Add-Content "$env:windir\System32\drivers\etc\hosts" -Value $newEntry
CheckHostsEntry $Address $FullyQualifiedName
}