Bläddra i källkod

Upload files to ''

delta 2 år sedan
förälder
incheckning
865ec2c972
1 ändrade filer med 38 tillägg och 0 borttagningar
  1. 38
    0
      Change IPaddress.ps1

+ 38
- 0
Change IPaddress.ps1 Visa fil

@@ -0,0 +1,38 @@
1
+if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
2
+    Start-Process PowerShell -Verb RunAs "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$pwd'; & '$PSCommandPath';`"";
3
+    exit;
4
+}
5
+Get-NetAdapter
6
+
7
+$ifIndex = read-host "Interface Index:"
8
+$NetworkInput = read-host "Network (First 3 Octets):"
9
+$HostInput = Read-Host "Host address (Last Octet):"
10
+$IPAddress = $NetworkInput +"."+$HostInput
11
+$SubnetmaskInput = read-host "Subnet Mask Or Last Octet(/24):"
12
+if($SubnetmaskInput -eq '') {$SubnetmaskInput= "24"}
13
+$DefaultGatewayInput = read-host "Default Gateway (Last Octet):"
14
+$DefaultGateway = $NetworkInput +"."+$DefaultGatewayInput
15
+
16
+Switch ($SubnetmaskInput)
17
+{
18
+24 {$Mask = $SubnetmaskInput}
19
+32 {$Mask = $SubnetmaskInput}
20
+30 {$Mask = $SubnetmaskInput}
21
+29 {$Mask = $SubnetmaskInput}
22
+0 {$Mask = 24}
23
+255 {$Mask = 32}
24
+252 {$Mask = 30}
25
+248 {$Mask = 29}
26
+
27
+Default {'Invalid Subnet Mask'}
28
+}
29
+
30
+ipconfig /all
31
+New-NetIPAddress -InterfaceIndex $ifIndex -IPAddress $IPAddress -PrefixLength $Mask -DefaultGateway $DefaultGateway
32
+ipconfig /all
33
+pause
34
+Remove-NetIPAddress -IPAddress $IPAddress -DefaultGateway $DefaultGateway
35
+Set-NetIPInterface -InterfaceIndex $ifIndex -Dhcp Enabled
36
+ipconfig /all
37
+ipconfig /renew
38
+pause

Powered by TurnKey Linux.