Recently when working on a project I need to change the gateway on a bunch of clients that had static IPs.
This PowerShell Script did the job
——-Begin Script———-
function Set-Gateway {
#Get NICS via WMI
$NICs = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $_ -Filter “IPEnabled=TRUE”
foreach($NIC in $NICs) {$Gateway = “192.168.0.254″
$NIC.SetGateways($Gateway)
}
}
function Get-FileName {
$computer = Read-Host “Please specify the location of the file containing the computer names”
return $computer
}
$f = Get-FileName
Get-Content $f | foreach {Set-Gateway}
——-End Script———-