Out 网络从 192.xyz 移至 10.uvw,我不想手动重新寻址 250 台计算机。我的想法是使用 powershell 脚本(针对单台电脑进行测试):
$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
}
}
Run Code Online (Sandbox Code Playgroud)
如果所有 NIC …
powershell ×1