-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSet-IPAddress.ps1
More file actions
49 lines (40 loc) · 1.48 KB
/
Set-IPAddress.ps1
File metadata and controls
49 lines (40 loc) · 1.48 KB
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
function SetNWAdapter {
$NWAdapter = $Args[0]
$IPAddress = $Args[1]
$SubNet = $Args[2]
$DefaultGW = $Args[3]
$DNS = $Args[4]
#Clear adapter settings
$nethelp = Get-NetIPConfiguration -InterfaceAlias $NWAdapter
$DefaultGWold = $nethelp.IPv4DefaultGateway.NextHop
if ($DefaultGWold) {
Remove-NetIPAddress -InterfaceAlias $NWAdapter -IpAddress * -DefaultGateway $DefaultGWold -Confirm:$false -ErrorAction SilentlyContinue
}
else {
Remove-NetIPAddress -InterfaceAlias $NWAdapter -IpAddress * -Confirm:$false
}
Set-DnsClientServerAddress -InterfaceAlias $NWAdapter -ResetServerAddresses
#Write new adapter settings
if ($DefaultGW){
New-NetIPAddress -InterfaceAlias $NWAdapter -IPAddress $IPAddress -PrefixLength 24 -DefaultGateway $DefaultGW
}
else {
New-NetIPAddress -InterfaceAlias $NWAdapter -IPAddress $IPAddress -PrefixLength 24
}
if ($DNS) {
Set-DnsClientServerAddress -InterfaceAlias $NWAdapter -ServerAddresses $DNS
}
}
# Main
Start-Sleep -Seconds 60
SetNWAdapter 'Ethernet' '178.63.97.11' '255.255.255.192' '178.63.97.1' '213.133.98.98'
#DNSServer : 213.133.98.98
#213.133.99.99
#213.133.100.100
Start-Sleep -Seconds 300
$adapters = Get-NetIPConfiguration
foreach ($adapter in $adapters)
{
SetNWAdapter $adapter.InterfaceAlias '178.63.97.11' '255.255.255.192' '178.63.97.1' '213.133.98.98'
Start-Sleep -Seconds 500
}