Tuesday, September 18, 2012

Bulk DHCP Reservations

Last week in our environment I was tasked with creating DHCP reservations for many computers.  If you have ever done a DHCP reservation one at a time when you have had tons to do, you know that the process would take a long, boring and tedious time.  I figured there has to be a way to simplify the process with a script of some sort.  Turns out I was right, but there is still a slight manual process to go through, but the time savings is huge.  Thank goodness for CSV files and powershell!

You will have to know the client names of your PC's you are looking to reserve.  In our case we knew they were all staff (teacher) PC's that were named with the same naming convention of: macbookpro-xxxx.

Here are the steps as I did it on server 2008r2

- Go into your DHCP management.
- Open up the scope where the computers you want reservations for grabbed their DHCP address from.
- Go into the Address Leases and sort them by name.
- Under "more actions" click on "export" and be sure to save the exported file as a csv file somewhere.
- Edit the CSV file with excel and remove all the rows containing the PC's you do not want reservations for.  
- Remove all the columns for the PC's you are reserving the IP for except for the IP, MAC address and Name column.
- You can either edit the IP address of each of the PC's in the CSV file manually to the reserved IP you want to give it, or come up with an excel formula for that column.
- Save the CSV and run this script.  (Be sure to read the script thoroughly and understand you will need to modify it for the file locations of where its reading the CSV file from and saving the powershell script its building to).
-Once you run the script it will build a powershell script with the info from the csv file you modified and saved.  Run that powershell script and your reservations will be in place!

Cheers!

No comments:

Post a Comment