?
Solved

Automate DHCP client computer add/remove via command line on Windows 2003 DHCP Server

Posted on 2005-04-11
8
Medium Priority
?
1,782 Views
Last Modified: 2011-09-20
We have a Windows 2003 server as DHCP server. Its a pain to enter in each MAC address and info by hand, I would like to automate the process. There are 4 fields that concern me and are necessary, the fifth field is optional to code. The list is below, its what the DHCP snap-in has...but I need this to be via commandline so I can automate it.

1. DHCP Reservation Name
2. MAC Address
3. IP Address
4. DHCP Description
5. (optional) Choice of DHCP/BOOTP/BOTH

Please tell me the cmd / exe with some sample info filled in (dhcp server, client info, etc).

Thanks
0
Comment
Question by:atkfrg56
  • 4
  • 3
8 Comments
 
LVL 16

Accepted Solution

by:
JamesDS earned 2000 total points
ID: 13754518
atkfrg56

I suggest you look into writing code with DHCPOBJS.DLL from the Windows 2000 Resource Kit.
This code will create a reservation:

Sub CreateDHCPReservations()

    ' Error handler, rem out for debugging
    On Error Resume Next

    ' Connect to the Target DHCP Server
    Set oDHCPServer        = oDHCPManager.Servers.Connect(strTargetDHCPServer)
   
    ' Create new Reservation Object
    strExecute            = "Set oDHCPReservation = oDHCPServer.Scopes(""" & strIPReference & """).Reservations.CreateNew"
    Execute(strExecute)
   
    With oDHCPReservation
   
        .Name        = strReservationName
        .UniqueID    = strReservationMAC
        .Address    = strReservationIP
        .Comment    = strReservationDescription
        .Update
   
    End With
   
    ' Close connection to DHCP Server
    oDHCPServer.Disconnect
   
End Sub

Cheers

JamesDS
0
 
LVL 9

Expert Comment

by:joedoe58
ID: 13754692
Excuse the question but why do you enter this info by hand into DHCP? The whole idea with DHCP is that it is dynamical. (hope i spelled that word right :-)
0
 
LVL 2

Author Comment

by:atkfrg56
ID: 13754808
JamesDS,
I will take a look at the info and get back to you, thx.

joedoe58,
We have 500 computers, 150 of those are laptops with a wireless card (so 2 they MAC addresses, need 2 entries) and we plan to purchase 100 more PCMCIA wifi cards for laptops not on the network...so thats 200 more MACs. So that all totals about 1000 entries by hand.

 I have all the MACs in a text file and stuff, just need some code to write out a batch script and run it. Why automate?...because we rotate our computer such as we get new product X..... X goes to A, A goes to B, B's old laptops get recycled. I need to be able to delete all the entries and start from new next year because IPs and MACs will change. If I can automate it, it will take an hour instead of 2 weeks.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 16

Expert Comment

by:JamesDS
ID: 13754921
atkfrg56
I wrote the orginal code a few years ago, it was designed to automatically set 2300 reservations on 2 DHCP servers with a total of 410 scopes. There is a lot of code either side of the bit I posted to read a text file and parse the results, but you have the really useful stuff there!

Cheers

JamesDS
0
 
LVL 2

Author Comment

by:atkfrg56
ID: 13756047
JamesDS,
I guess I can use VB6 for the script.

 Do i need any libraries or references to run the function, i get an error at line
 Execute(strExecute)

What is strIPReference?
thx
0
 
LVL 16

Assisted Solution

by:JamesDS
JamesDS earned 2000 total points
ID: 13759996
atkfrg56
I used VBScript - which is why you get an error at the Execute command. Save the code as a .VBS.

Sorry, forgot to tell you!

strIPReference is the Scope ID - minus the subnet notification. This is visible in the left hand window of the DHCP Manager MMC tool and is in the form xxx.xxx.xxx.0

So, a scope giving out 192.168.100.1 to 192.168.101.254 with a /23 (.254.0) subnet would have an strIPReference of "192.168.100.0)

Is that clear??

DHCPOBJS.DLL ships with a CHM file that explains how it works and provides a complete object model. You can use the tools that ship with VB to open up the DLL and expose the properties and methods.

Cheers

JamesDS
0
 
LVL 2

Author Comment

by:atkfrg56
ID: 13761049
Thx, I got this to work now. Why they call the scope 'strIPReference' I shall never know why [you dont have to answer that] :)
0
 
LVL 16

Expert Comment

by:JamesDS
ID: 13761072
atkfrg56

Welcome

Actually, that's my code - I just picked a name that meant something to me!

Cheers
JamesDS
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Currently, there is an issue with being able to copy values from an external application to a dropdown list in Project Web Access (PWA).  The standard copy and paste methods don't seem to work properly. Here is a way to accomplish this task to s…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question