Hi,
This is a very common task which is nearly performed by every End-user and IT Admin and Engineers. Normally we use "IPCONFIG /Release" to release the IP-address and "IPconfig / Renew" to renew or getting a new IP Address.
In some powershell script you may need to do this ip config /release and renew task. We can use native "IPconfig" command to achieve this. But there is an another way to do the same. Using WMI.
Download the script from here :
In variable $ethernet we are querying class Win32_NetworkAdapterConfiguration and using where-Object cmdlet we are choosing those adapter which have IP Enabled and have DHCP Enabled selected in there IP Configuration
than on each adapter we are using wmi method ReleaseDHCPLease() first and then RenewDHCPLease() .
################################
$ethernet = Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where { $_.IpEnabled -eq $true -and $_.DhcpEnabled -eq $true}
foreach ($lan in $ethernet) {
Write-Host "Flushing IP addresses" -ForegroundColor Yellow
Sleep 2
$lan.ReleaseDHCPLease() | out-Null
Write-Host "Renewing IP Addresses" -ForegroundColor Green
$lan.RenewDHCPLease() | out-Null
Write-Host "The New Ip Address is "$lan.IPAddress" with Subnet "$lan.IPSubnet"" -ForegroundColor Yellow
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.