Batch Script to Install and Configure DHCP Server in Windows:


Note:
 Put comment (::) wherever required and set variables as per your requirement:

:: Script Starts here

@echo off
:: set variable

set dhcp-server=10.0.0.2
set netmask=255.255.255.0
set scope=10.0.0.0
set scope-name="scope1"

::IP Range
set start-address=10.0.0.50
set end-address=10.0.0.100

::Exclusion Range
set ex-start-address=10.0.0.60
set ex-end-address=10.0.0.65

::Scope Options
set gateway-address=10.0.0.1

:: Predefined Options (to add):
set option-name=MyApplication-Server
set data-type=IPADDRESS
set option-code=222

::Installing and Configuring DHCP
servermanagercmd -install dhcp

::Setting DHCP Service Startup-type: Automatic
sc config dhcpserver start= auto

::Starting DCHP Server Service
net start dhcpserver

::Creating Scope
netsh dhcp server %dhcp-server% add scope %scope% %netmask% %scope-name%

::Adding IP Range
netsh dhcp server %dhcp-server% scope %scope% add iprange %start-address% %end-address%

::Adding Exclusion Range
netsh dhcp server %dhcp-server% scope %scope% add excluderange %ex-start-address% %ex-end-address%

::Configure Scope Option
netsh dhcp server %dhcp-server% scope %scope% set optionvalue 003 IPADDRESS %gateway-address%

:: Set Predefined Options:
netsh dhcp server add optiondef %option-code% %option-name% %data-type%
::netsh dhcp server add optiondef 223 app-port word

:: Script Ends Here 


To uninstall DHCP Server:

servermanagercmd -remove dhcp -restart

Where: -restart switch will restart the machine if required.


Connect With Us
Instant Query
Your Name :
Email Address :
Message :