1234567891011121314151617181920212223242526272829303132333435363738 |
- if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
- Start-Process PowerShell -Verb RunAs "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$pwd'; & '$PSCommandPath';`"";
- exit;
- }
- Get-NetAdapter
-
- $ifIndex = read-host "Interface Index:"
- $NetworkInput = read-host "Network (First 3 Octets):"
- $HostInput = Read-Host "Host address (Last Octet):"
- $IPAddress = $NetworkInput +"."+$HostInput
- $SubnetmaskInput = read-host "Subnet Mask Or Last Octet(/24):"
- if($SubnetmaskInput -eq '') {$SubnetmaskInput= "24"}
- $DefaultGatewayInput = read-host "Default Gateway (Last Octet):"
- $DefaultGateway = $NetworkInput +"."+$DefaultGatewayInput
-
- Switch ($SubnetmaskInput)
- {
- 24 {$Mask = $SubnetmaskInput}
- 32 {$Mask = $SubnetmaskInput}
- 30 {$Mask = $SubnetmaskInput}
- 29 {$Mask = $SubnetmaskInput}
- 0 {$Mask = 24}
- 255 {$Mask = 32}
- 252 {$Mask = 30}
- 248 {$Mask = 29}
-
- Default {'Invalid Subnet Mask'}
- }
-
- #ipconfig /all
- New-NetIPAddress -InterfaceIndex $ifIndex -IPAddress $IPAddress -PrefixLength $Mask -DefaultGateway $DefaultGateway
- #ipconfig /all
- pause
- Remove-NetIPAddress -IPAddress $IPAddress -DefaultGateway $DefaultGateway
- Set-NetIPInterface -InterfaceIndex $ifIndex -Dhcp Enabled
- #ipconfig /all
- ipconfig /renew
- pause
|