title: Powershell script to check IP connection and delete IP address lease
body: <p>I am looking for a Powershell script to check IP connection and delete IP address lease if the connection is False. Here is what I have so far.</p>
  
  <pre><code>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}
  </code></pre>
  
  <p>I am thinking my syntax is wrong here but can't quite figure it out. This is on a 2008 server.</p>
  
  <p>Bonus: Obviously I am using this to check a scope and any addresses that are not in use I want to remove them. I could just change the lease time to less but that is not policy so I have to come up with another way. So if there is a way to go from 10.5.5.100 through 10.5.5.254 removing any IPs that are not active that would be great. </p>