Alan's sysadmin Blog

Working smarter not harder

Archive for July, 2010

Change default gateway on clients with static IP’s using PowerShell

Posted by Alan McBurney on July 29, 2010

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———-

Posted in PowerShell, Windows Servers | Tagged: | 2 Comments »

 
Follow

Get every new post delivered to your Inbox.

Join 153 other followers