-
Notifications
You must be signed in to change notification settings - Fork 0
/
Set-PreferIPv4.ps1
101 lines (92 loc) · 2.17 KB
/
Set-PreferIPv4.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
94
95
96
97
98
99
100
<#
.SYNOPSIS
Sets prefix policy to prefer IPv4 over IPv6.
.DESCRIPTION
Sets prefix policy to prefer IPv4 over IPv6.
.NOTES
Version: 1.0
Author: Mike McGhee
Creation Date: 08/28/2017
Purpose/Change: Initial script commit
.EXAMPLE
Basic usage
.\Set-PreferIPv4.ps1
#>
$prefixList = @(
@{
Name = '3ffe::/16'
Precedence = 1
Label = 12
}
@{
Name = 'fec0::/10'
Precedence = 1
Label = 11
}
@{
Name = '::/96'
Precedence = 1
Label = 4
}
@{
Name = 'fc00::/7'
Precedence = 3
Label = 13
}
@{
Name = '2001::/32'
Precedence = 5
Label = 5
}
@{
Name = '2002::/16'
Precedence = 20
Label = 3
}
@{
Name = '::/0'
Precedence = 30
Label = 2
}
@{
Name = '::1/128'
Precedence = 40
Label = 1
}
@{
Name = '::ffff:0:0/96'
Precedence = 50
Label = 0
}
)
try
{
if ((Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters' | Select-Object -ExpandProperty 'DisabledComponents') -eq 32)
{
Write-Output "Prefix policy setting exists in Registry."
}
else
{
Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\" -Name "DisabledComponents" -Value 0x20
Write-Output "Prefix policy setting created in Registry."
}
}
catch
{
New-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\" -Name "DisabledComponents" -Value 0x20 -PropertyType "DWord"
Write-Output "Prefix policy setting created in Registry."
}
$pingtest = Test-NetConnection localhost
if ($pingtest.RemoteAddress -eq '::1')
{
Write-Output "Prefix policy is not active. Setting now..."
foreach ($prefix in $prefixList)
{
& netsh interface ipv6 set prefixpolicy $prefix.Name $prefix.Precedence $prefix.Label
}
Write-Output "Prefix policy set to active."
}
else
{
Write-Output "Prefix policy is already active."
}