|
I
wrote this as a VBScript wrapper to NETSH. We have used this to reload
4000 scopes on multiple DHCP servers. You can run this via a batch file
and supply all the required parameters or use it to run interactively for
creating new scopes. Up to you.
As
always test it in a lab prior to production use.
I can
not be responsible for the results of running this script.
*************SCRIPT BEGIN****************
Option
Explicit
'On Error Resume next 'wscript.echo "" 'wscript.echo "NewDHCP.vbs (c) Edward Parker, Buchanan Associates" 'wscript.echo " This script will add Subnets in DHCP" Dim
sDHCPServer, sScope, sScopeSub, sScopeName, sRangeBegin, sRangeEnd,
sOption
Dim sDefaultGW, sFQDN, sResults, sScopeDesc Dim oShell If
wscript.arguments.count > 0 then
If wscript.arguments(0) = "/?" OR wscript.arguments(0) = "?" OR
wscript.arguments(0) = "-?" then
wscript.echo "" wscript.echo "USAGE:" wscript.echo "NewDHCP <DHCPSERVERIP> <SCOPE> <SCOPE SUBNET> <NAME> <DESCRIPTION> <START IP RANGE> <END IP RANGE> <Default GW> <DOMAIN NAME>" wscript.echo "" wscript.echo "EXAMPLE:" wscript.echo "NewDHCP 192.168.1.1 5.5.5.0 255.255.255.0 ""Scope Name"" ""ScopeDescription"" 5.5.5.100 5.5.5.150 5.5.5.1 <domain>.com" wscript.quit End If End
If
if
wscript.arguments.count < 9 OR wscript.arguments.count > 9
then
If wscript.arguments.count < 1 then MsgBox "No command line arguments detected" else MsgBox "Wrong Number of Arguments" End If sDHCPServer = Inputbox("What is the DHCP Server IP Address?") sScope = Inputbox("What is the Scope to add?") sScopeSub = InputBox("What is the Scope's Subnet?") sScopeName = InputBox("What is the Scope's Name?") sScopeDesc = InputBox("What is the Scope's Description?") sRangeBegin = InputBox("What is the Scope's Range Starting IP?") sRangeEnd = InputBox("What is the Scope's Range Ending IP?") sDefaultGW = InputBox("What is the Default Gateway?") sFQDN = InputBox("What is the domain name?") else sDHCPServer = wscript.arguments(0) sScope = wscript.arguments(1) sScopesub = wscript.arguments(2) sScopeName = wscript.arguments(3) sScopeDesc = wscript.arguments(4) sRangeBegin = wscript.arguments(5) sRangeEnd = wscript.arguments(6) sDefaultGW = wscript.arguments(7) sFQDN = wscript.arguments(8) 'wscript.echo sScopeName & " " & sScopeDesc End IF
Set oShell =
CreateObject("wscript.shell")
if err <> 0 then opps "Create Shell", err.number,err.description,err.source wscript.echo "Adding Scope " & sScope 'wscript.echo "netsh dhcp server " & sDHCPServer & " add scope " & sScope & " " & sScopeSub & " """ & sScopeNAme & """ """ & sScopeDesc & """" sResults = oShell.Run("netsh dhcp server " & sDHCPServer & " add scope " & sScope & " " & sScopeSub & " """ & sScopeNAme & """ """ & sScopeDesc & """",0, True) If sResults <> 0 then opps "Add Scope Failure "&sScope,sResults,"?","?" sResults = 0 End if oShell.Run "netsh dhcp server " & sDHCPServer & " scope " & sScope & " add iprange " & sRangeBegin & " " & sRangeEnd,0, True If sResults <> 0 then opps "Add IP Range Failure "&sScope,sResults,"?","?" sResults = 0 End if 'oShell.Run "netsh dhcp server " & sDHCPServer & " scope " & sScope & " add excluderange " & <beginIP> & " " & <EndIP>,0, True 'If sResults <> 0 then ' opps "Add Exclusion Failure",sResults,"?","?" ' sResults = 0 'End if oShell.Run "netsh dhcp server " & sDHCPServer & " scope " & sScope & " set optionvalue 003 IPADDRESS " & sDefaultGW,0, True If sResults <> 0 then opps "Add Scope Option 003 Failure "&sScope,sResults,"?","?" sResults = 0 End if oShell.Run "netsh dhcp server " & sDHCPServer & " scope " & sScope & " set optionvalue 015 STRING " & sFQDN,0, True If sResults <> 0 then opps "Add Scope Option 015 Failure "&sScope,sResults,"?","?" sResults = 0 End if oShell.Run "netsh dhcp server " & sDHCPServer & " scope " & sScope & " set state 1",0, True If sResults <> 0 then opps "Scope Set State Failure "&sScope,sResults,"?","?" sResults = 0 End if writeMe "Success: Scope Creation complete for " & sScope Sub Opps(Data, ErrMsgNum, errMsgDesc, ErrMsgsource) Dim oFSO,oFile wscript.echo "Error: Failed adding " & DATA & " " & ErrMSGNum & " " & ErrMsgDesc & " " & ErrMsgSource Set oFSO = createobject("Scripting.Filesystemobject") Set oFile = oFSO.OpenTextFile("c:\DHCPERRORS.txt",8,True) oFile.writeline "Error: Failed adding " & vbtab & DATA & vbtab & ErrMSGNum &vbtab& ErrMsgDesc &vbtab& ErrMsgSource err.clear wscript.quit End Sub Sub WriteMe(info)
Dim oFSO,oFile Set oFSO = createobject("Scripting.Filesystemobject") Set oFile = oFSO.OpenTextFile("c:\DHCPWORKS.txt",8,True) oFile.writeline info End Sub ****************END
SCRIPT*****************************
|
Title: Message
- RE: [ActiveDir] DHCP/Netsh - Other ways of working ... Burns, Clyde
- RE: [ActiveDir] DHCP/Netsh - Other ways of wor... FDiskThePC
- RE: [ActiveDir] DHCP/Netsh - Other ways of wor... Darren Mar-Elia
- RE: [ActiveDir] DHCP/Netsh - Other ways of wor... Robbie Allen
- RE: [ActiveDir] DHCP/Netsh - Other ways of wor... Burns, Clyde
- RE: [ActiveDir] DHCP/Netsh - Other ways of wor... Myrick, Todd (NIH/CIT)
- Parker, Edward
