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 都获得了新 IP,请使用 删除旧 IP Remove-NetIPAddress
。
目前,它$cimSess
没有按预期工作,但我的主要问题是:我是否走在正确的轨道上,或者是否有更好/更快/更容易/...的方法来做到这一点?或者我完全错了并且错过了一些东西?
您应该使用 DHCP 为您的网络配置 IP 地址。然后,所有计算机都启用 DHCP,并从 DHCP 服务器获取正确的 IP 地址。
归档时间: |
|
查看次数: |
200 次 |
最近记录: |