Powershell script to check IP connection and delete IP address lease -
Powershell script to check IP connection and delete IP address lease -
i looking powershell script check ip connection , delete ip address lease if connection false. here have far.
if (test-connection -computername 10.5.5.100 -count 1 -quiet) -eq false {netsh dhcp server \\computername scope 10.15.1.0 delete lease 10.15.1.100} if (test-connection -computername 10.5.5.100 -count 1 -quiet -eq false) {netsh dhcp server \\computername scope 10.15.1.0 delete lease 10.15.1.100}
i thinking syntax wrong here can't quite figure out. on 2008 server.
bonus: using check scope , addresses not in utilize want remove them. alter lease time less not policy have come way. if there way go 10.5.5.100 through 10.5.5.254 removing ips not active great.
just do:
if (test-connection -computername 10.5.5.100 -count 1 -quiet) {} else {netsh dhcp server \\computername scope 10.15.1.0 delete lease 10.15.1.100}
or if want save result of test:
$live = test-connection -computername 10.5.5.100 -count 1 -quiet if (!$live) { netsh dhcp server \\computername scope 10.15.1.0 delete lease 10.15.1.100 }
powershell
Comments
Post a Comment