-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ps1
59 lines (44 loc) · 1.7 KB
/
main.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
# Disable network adapters or IP protocols if the network name contains $notWanted.
# You can see the network name, for example, with the PowerShell command Get-NetConnectionProfile.
## configuration
$notWanted = "labor" # Not case-sensitive. It is sufficient to enter a part of the name.
$disableCompletely = $false
$disableIPv4 = $true
$disableIPv6 = $true
# When $disableCompletely is true, the network adapter ist disabled and the other variables are ignored.
# Otherwise the network adapter stays enabled with the IP protocols switched on or off according to the variables.
# WARNING: This script only detects an active network adapter. If you have completely disabled it or switched off
# both IP protocols, you have to reactivate ist manually.
## script
$notWanted = $notWanted.ToUpper()
ForEach ($profile in Get-NetConnectionProfile)
{
if ($profile.Name.ToUpper().Contains($notWanted))
{
$adapters = Get-NetAdapter | Where InterfaceIndex -eq $profile.InterfaceIndex
$adapter = $adapters[0]
if ($disableCompletely)
{
Disable-NetAdapter $adapter.Name -Confirm:$false
}
else
{
if ($disableIPv4)
{
Disable-NetAdapterBinding $adapter.Name -ComponentID ms_tcpip
}
else
{
Enable-NetAdapterBinding $adapter.Name -ComponentID ms_tcpip
}
if ($disableIPv6)
{
Disable-NetAdapterBinding $adapter.Name -ComponentID ms_tcpip6
}
else
{
Enable-NetAdapterBinding $adapter.Name -ComponentID ms_tcpip6
}
}
}
}