Today we’ve to create up to 50 DHCP Scopes to implement the vLAN concept with 802.1x network authorization.
To do this job by hand isn’t easy, so I create a powershell script which creates a netsh script out of a .csv file.
##============================================================================================
##============================================================================================
## SCRIPT………: Create-Scope.ps1
## AUTHOR………: sirhartmann
## EMAIL……….:
## VERSION……..: 1
## DATE………..: 2013.02.04
##
## DESCRIPTION….: Creates a CMD file to create numerous DHCP scopes
##
## NOTES……….: Requires CSV file with these fields: “SCOPER”,”MASK”,”NAME”,DESC” “ROUTER”,”STARTIP1″,”ENDIP1″,”STARTIP2″,”ENDIP2″,”DNSSUFFIX”,”BROADCAST”
##============================================================================================# IP address of DHCP server
$DHCPServer1 = “10.0.8.10”
$DHCPServer2 = “10.0.8.11”#IP address of DNS servers
$DNS1 = “10.0.8.1”
$DNS2 = “10.0.8.2”# Name of output batch file
$outputfile1 = “D:\DHCPscopes.cmd”# Read data from csv file D:\Input.csv
$scopes = Import-Csv ‘D:\input.csv’
foreach ($scope in $scopes) {
### DHCP Server 1
“netsh dhcp server $DHCPServer1 add scope ” + $scope.scoper + ” ” + $scope.mask + ” ” + $scope.name + ” ” + $scope.desc >> $outputfile1
“netsh dhcp server $dhcpserver1 scope ” + $scope.scoper + ” ” + “set optionvalue 3 IPADDRESS” + ” ” + $scope.router >> $outputfile1
“netsh dhcp server $dhcpserver1 scope ” + $scope.scoper + ” ” + “set optionvalue 6 IPADDRESS” + ” ” + $DNS1 + ” ” + $DNS2 >> $outputfile1
“netsh dhcp server $dhcpserver1 scope ” + $scope.scoper + ” ” + “set optionvalue 15 STRING” + ” ” + $scope.dnssuffix >> $outputfile1
“netsh dhcp server $dhcpserver1 scope ” + $scope.scoper + ” ” + “add iprange” + ” ” + $scope.startip1 + ” ” + $scope.endip1 >> $outputfile1
“netsh dhcp server $dhcpserver1 scope ” + $scope.scoper + ” ” + “set optionvalue 28 IPADDRESS” + ” ” + $scope.broadcast >> $outputfile1
“netsh dhcp server $dhcpserver1 scope ” + $scope.scoper + ” ” + “set optionvalue 51 DWORD 28800” >> $outputfile1
“netsh dhcp server $DHCPserver1 scope ” + $scope.scoper + ” ” + “set state 0″ >> $outputfile1
” ” >> $outputfile1
}foreach ($scope in $scopes) {
### DHCP Server 2
“netsh dhcp server $DHCPServer2 add scope ” + $scope.scoper + ” ” + $scope.mask + ” ” + $scope.name + ” ” + $scope.desc >> $outputfile1
“netsh dhcp server $dhcpserver2 scope ” + $scope.scoper + ” ” + “set optionvalue 3 IPADDRESS” + ” ” + $scope.router >> $outputfile1
“netsh dhcp server $dhcpserver2 scope ” + $scope.scoper + ” ” + “set optionvalue 6 IPADDRESS” + ” ” + $DNS1 + ” ” + $DNS2 >> $outputfile1
“netsh dhcp server $dhcpserver2 scope ” + $scope.scoper + ” ” + “set optionvalue 15 STRING” + ” ” + $scope.dnssuffix >> $outputfile1
“netsh dhcp server $dhcpserver2 scope ” + $scope.scoper + ” ” + “add iprange” + ” ” + $scope.startip2 + ” ” + $scope.endip2 >> $outputfile1
“netsh dhcp server $dhcpserver2 scope ” + $scope.scoper + ” ” + “set optionvalue 28 IPADDRESS” + ” ” + $scope.broadcast >> $outputfile1
“netsh dhcp server $dhcpserver2 scope ” + $scope.scoper + ” ” + “set optionvalue 51 DWORD 28800” >> $outputfile1
“netsh dhcp server $DHCPserver2 scope ” + $scope.scoper + ” ” + “set state 0″ >> $outputfile1
” ” >> $outputfile1
}# End of Script
################
CSV File:
“SCOPER”,”MASK”,”NAME”,”DESC”,”ROUTER”,”STARTIP1″,”ENDIP1″,”STARTIP2″,”ENDIP2″,”DNSSUFFIX”,”BROADCAST”
“10.0.8.0”,”255.255.255.0″,”vLAN1″,”ScopevLAN1″,”10.0.8.1″,”10.0.8.50″,”10.0.8.149″,”10.0.8.150″,”10.0.8.249″,”iteh.local”,”10.0.8.255″