我正在使用RenewDHCPLease()更新系统的IP地址。
RenewDHCPLease()和ipconfig /renew的确切区别是什么?ReleaseDHCPLease()之前使用RenewDHCPLease()?如果是的话,为什么?下面是我的代码:
try {
$ips = Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where { $_.IpEnabled -eq $true -and $_.DhcpEnabled -eq $true} -ErrorAction Stop
if (!$ips) {
Write-Output "`nDHCP is not Enabled on this system"
Exit
}
foreach ($ip in $ips) {
Write-Output "`nRenewing IP Addresses"
$ip.RenewDHCPLease() | Out-Null
if ($?) {
Write-Output "IP address has been renewed for this system"
}
else {
Write-Error "IP Address Could not be renewed"
}
}
}
catch {
$_.Exception.Message
}发布于 2019-07-03 08:45:33
ReleaseDHCPLease 释放绑定到特定DHCP启用网络适配器的IP地址。 RenewDHCPLease 更新特定DHCP启用的网络适配器上的IP地址。
没有必要在ReleaseDHCPLease之前使用RenewDHCPLease,因为旧地址被释放了,使用RenewDHCPLease时会自动获得一个新地址。
Get-WmiObject Win32_NetworkAdapterConfiguration -Filter 'IpEnabled=True AND DhcpEnabled=True' | Foreach-Object{
$_.RenewDHCPLease()
}您还可以使用RenewDHCPLeaseAll方法一次性对它们进行更新。希望这会有所帮助:)
https://stackoverflow.com/questions/54669868
复制相似问题