小编Tho*_*s P的帖子

使用 Powershell 将整个网络的 IP 地址从 192.xyz 更改为 10.uvw

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
推荐指数
1
解决办法
200
查看次数

标签 统计

powershell ×1