Powershell : renew remote IP address

We wrote this at GiraffeIT.com. If you know the remote IP or DNS name of a machine it will help you renew a DHCP lease and flush the DNS.

Very useful if you have a remote machine with a scope change and its not being reflected.

 

write-host “—————————–”
write-host “DHCP lease renewal + flushDNS”
write-host “—————————–”
$machine = read-host “IP/Name of machine needing lease renewal ? ”
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $machine | Where { $_.IpEnabled -eq $true -and $_.DhcpEnabled -eq $true} | ForEach-Object -Process {$_.RenewDHCPLease()}
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $machine | Where { $_.IpEnabled -eq $true -and $_.DhcpEnabled -eq $true} | ForEach-Object -Process {ipconfig /flushdns}

Leave a Reply

Your email address will not be published. Required fields are marked *