You can remove multiple scopes from your DHCP server by using this simple script which uses the Remove-DhcpServerv4Scope PowerShell cmdlet.

The script assumes you have scope IDs in a series (I have scope IDs of 10.0.0.0, 11.0.0.0 and 12.0.0.0).

Delete Multiple DHCP Scopes Using PowerShell

Step 1. Open notepad and copy/paste the following script and save the file with .ps1 extension. Be sure to replace your DHCP name in the script and loop variables (according to the range of scopes you have)

for ($i = 10;$i -lt 13;$i++)

{

$ScpID = $i.ToString() + ".0.0.0"

Remove-DhcpServerv4Scope -computername "Server2016.yourdomain.com" -ScopeId $ScpID -Force

}

Step 2. Open PowerShell with elevated privileges and execute the above script from step 1

How to Delete Multiple DHCP Scopes Using PowerShell

One thought on “How to Delete Multiple DHCP Scopes Using PowerShell

  • Permalink

    Hi,
    I used your script and improved something, now it automatically searches for more subnets. Hope this helps.

    for ($i = 0;$i -lt 8;$i++)

    {
    for ($j = 0;$j -lt 200;$j++)
    {

    for ($k = 0;$k -lt 255;$k++)
    {

    $ScpID = “10.”+ $i.ToString() + “.” + $j.ToString()+ “.0″+ $k.ToString()

    Remove-DhcpServerv4Scope -computername “SRVNEDDHC002.sonangol.pvt” -ScopeId $ScpID -Force

    }
    }
    }

    Thanks

    Reply

Leave a Reply

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

*

Ad #native_company# — #native_desc# #native_cta#