0

I want to delete all DHCP leases and reservation from server WSKELLER. From the documentation I seem to understand that this would be accomplished with:

Get-DhcpServerv4Scope -ComputerName WSKELLER | Remove-DhcpServerv4Lease -ComputerName WSKELLER

The cmdlet does find all the leases, yet it throws for each lease the following error:

Remove-DhcpServerv4Lease : Failed to delete lease 10.10.12.32 from scope 10.10.0.0 on DHCP server WSKELLER.
At C:\admin\removeDhcpDns.ps1:8 char:48
+ ... mputerName WSKELLER | Remove-DhcpServerv4Lease -ComputerName WSKELLER + 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ResourceExists: (10.10.12.32:root/Microsoft/...cpServerv4Lease) [Remove-DhcpServerv4Lease], CimException
+ FullyQualifiedErrorId : DHCP 20019,Remove-DhcpServerv4Lease

Obviously I am doing some mistake. But which one?

aag
  • 407
  • 1
  • 6
  • 19
  • Does the account you use have the required permissions to remove the leases? – Persistent13 Jul 14 '16 at 22:56
  • I start the script from an administrative (elevated) powershell. Should I do more? – aag Jul 15 '16 at 11:22
  • Possibly, if the user account you are launching the shell from does not have permissions to the write to the DHCP server you will not be able to remove the leases. – Persistent13 Jul 15 '16 at 16:44

1 Answers1

3

From your error: + FullyQualifiedErrorId : DHCP 20019,Remove-DhcpServerv4Lease

From: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363378(v=vs.85).aspx

ERROR_DHCP_RESERVED_CLIENT 20019 The specified DHCP client is a reserved client.

It looks like you're trying to delete a reservation. If that is intentional, then you will need to use the Remove-DhcpServerv4Reservation cmdlet instead.

learley
  • 459
  • 2
  • 5