Skip to content

Instantly share code, notes, and snippets.

@nitrocode
Last active November 16, 2015 17:53
Show Gist options
  • Save nitrocode/3e5932b7e39a6ba52566 to your computer and use it in GitHub Desktop.
Save nitrocode/3e5932b7e39a6ba52566 to your computer and use it in GitHub Desktop.
Powershell 2 script to change the IP with arguments
# Usage: powershell -File SetIP.ps1 -ip "101.54.149.103"
# Works on Windows 7 64bit
# get params
param (
[string]$ip = "101.54.149.106",
[string]$gw = "101.54.149.1",
[string]$sub = "255.255.255.0",
[string]$dns1 = "101.61.241.311",
[string]$dns2 = "101.61.251.311"
)
Write-Host "IP Addr: $ip"
Write-Host "Gateway: $gw"
Write-Host "Subnet: $sub"
Write-Host "DNS1: $dns1"
Write-Host "DNS2: $dns2"
# change IP address
$wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'"
$ret = $wmi.EnableStatic($ip, $sub)
$ret = $wmi.SetGateways($gw, 1)
# set dns
$ret = $wmi.SetDNSServerSearchOrder([$dns1, $dns2])
# set suffixes (suffices?)
$ret = $wmi.SetDNSServerSearchOrder("old.domain.com domain.com new.newdomain.com newdomain.com")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment