Out Network moves from 192.x.y.z to 10.u.v.w and I don't want to readdress 250 Computers by hand. My idea is to use a powershell script (test for a single pc):
$oldIp='192.168.100.1'
$newIp='10.11.12.13'
$newGw='10.11.12.254'
$newLen='24'
$adminCred = Get-Credential -UserName ourdomain\myAdminAccount -Message 'Enter Password'
ForEach ($Adapter in (Get-WmiObject Win32_NetworkAdapter -Filter "NetEnabled='True'" -ComputerName $oldIp )){
$wmiQuery = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index = '$($Adapter.Index)'" -ComputerName $oldIp
if( $wmiQuery.IPAddress -contains $oldIp ){
$pcName=[system.net.dns]::gethostentry($lavIp) | Select-Object -ExpandProperty HostName
$cimSess=New-CimSession -SkipTestConnection -Credential $adminCred -ComputerName $pcName
New-NetIPAddress -CimSession $cimSess -InterfaceIndex $Adapter.Index -IPAddress $newIp -PrefixLength $newLen -DefaultGateway $newGw
}else{
## do not touch this nic
}
}
If all NICs got it's new IP, remove the old IP with Remove-NetIPAddress
.
Currently, the $cimSess
does not work as expected, but my main question is: Am I on the right track, or is there a better/faster/easier/... way to do this? Or am I completely wrong and missed something?