Powershell & DHCP Scopes

Really quick one this; I had a DHCP server with 136 scopes on it that I needed to disable and so the following script was born. It takes 1 argument – the hostname of the DHCP server in question; leave blank for localhost:

#DHCP Server-wide scope disabler
#Adam Beardwood 16/02/2010
#v1.0 - Initial Release
Disables all DHCP scopes on the specified server
DNS name or IP of server to work with
	[Parameter(Mandatory=$false,ParameterSetName="Server",ValueFromPipelineByPropertyName=$true,Position=0,Helpmessage="DNS name or IP of server to work with")]$Server = "localhost"
$Server = "\\$Server"
$scopes = netsh dhcp server $server show scope
foreach($scope in $scopes){
$regex = [regex]"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
$ip = $scope | foreach {$regex.Matches($_) | foreach {$_.Captures[0].Value}}
if($ip -ne $null){
& netsh dhcp server $server scope $ip[0] set state 0

Published by


I am the person responsible for all this, that's all you need to know.

2 thoughts on “Powershell & DHCP Scopes”

  1. I must say Adam, your script is a HUGE time saver. We have a customer that has nearly 500 scopes and we are doing a migration of their DHCP to a virtual server and I needed to deactivate all those scopes as we started testing. I’m glad I came across this script. Cheers!


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.