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
Avatar

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn

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

  • Avatar
    May 16, 2019 at 11:55 am
    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 *

*