-
Notifications
You must be signed in to change notification settings - Fork 1
/
IPconfig.ps1
56 lines (48 loc) · 1.42 KB
/
IPconfig.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
Function Get-Menu{
Clear-Host
Write-Host "IP Settings"
Write-host "1.- Static IP"
Write-Host "2.- IP through DHCP"
Write-Host "3.- Exit"
}
Function Get-Adaptader {
Write-Host "IP Configuration"
Get-NetAdapter|ft -AutoSize
$script:interface = Read-Host "Set adapter Name (IfIndex)"
$script:name = Read-Host "Set its name (name)"
#Remove IP address
Remove-NetIPAddress -InterfaceIndex $interfaz -Confirm:$false
Remove-NetRoute -InterfaceIndex $interfaz -Confirm:$false
}
Function Static-IP {
Get-NetAdapter
#Establecer IP Fija
$ip = Read-host "Set the IP you want to use"
$netmask = Read-Host "Set the net mask (Number of host bits)"
$gateway = Read-Host "Set the gateway"
$dns1 = Read-host "Set the first DNS"
$dns2 = Read-host "Set the first DNS"
New-NetIPAddress -InterfaceIndex $interfaz $ip -PrefixLength $netmask -DefaultGateway $gateway
Set-DnsClientServerAddress -InterfaceIndex $interface -ServerAddresses ("$dns1","$dns2")
Restart-NetAdapter -Name $name
}
Function IP-Dhcp {
Get-NetAdapter
#IP through DHCP
Set-NetIPInterface -InterfaceIndex $interface -Dhcp enabled
Set-DnsClientServerAddress -InterfaceIndex $interface -ResetServerAddresses
#Restart the adapter
Restart-NetAdapter -Name $name
}
#Start menu
do{
Get-Menu
$option = Read-Host "Elija una opción"
switch ($option){
'1'{Static-IP}
'2'{IP-Dhcp}
'3'{exit}
Default {Write-Host "Please, choose a correct option"}
}
$intro = Read-Host "Pulse intro para continuar"
}while ($true)