Jump to content

Is there a way of creatin DHCP reservations from a CSV file?


Recommended Posts

Posted

Does anyone know of a way that I can create all of my DHCP reservations from a CSV file? :?

 

It would really help as I'm trying to put this network in order and get some order.

 

Thanks in advance

 

Gonk

Posted

I don't think you can do this from the GUI, but you should be able to with a bit of scripting. e.g. using vbscript and the NETSH command:

 

' script to bulk create DHCP reservations from a .csv file

' Set a couple of constants
' Set following line to IP address of DHCP server, or leave blank for local computer
Const DHCPServer = "" 
' Set following line to address scope where reservation is to be added
Const SCOPE = "192.168.1.0" 
' Set following line to location of .csv file containing the reservation to be added
Const FileLocation = "C:\reservations.csv" 

' read in the csv file
' format:
' ,,,

Const forReading = 1

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objCSVFile = objFSO.OpenTextFile(FileLocation,forReading)

' Process csv file
Do While objCSVFile.AtEndOfStream <> True
' read in a line from the csv file
strLine = objCSVFile.ReadLine

' seperate the cells on the line
arrCells = split(strLine,",",-1,1)

' get the values from the cells
strIP = arrCells(0)
strMAC = arrCells(1)
strClientName = arrCells(2)
strDescription = arrCells(3)

' build the NETSH command string
strCmd = "netsh dhcp server " & DHCPServer & " scope " & SCOPE & " add reservedip " & _
             strIP & " " & strMAC & " " & strClientName & " """ & strDescription & """"

' run the NETSH command
objShell.Run strCmd, 1, TRUE
Loop

' All done so close the csv file
objCSVFile.close

' Clean up objects
Set objCSVFile = Nothing
Set objFSO = Nothing
Set objShell = Nothing

WScript.Echo "All done."

 

I have not fully tested this, so as always make a backup before using it.

 

Hope that is of some help,

 

Iain.

Posted

Use...

 

netsh dhcp server \\servername dump >c:\dhcp.txt

 

... to get your current list. Look for the reservation section:

 

    
  # ======================================================================
  #  Start Add ReservedIp to the Scope : IP of Server Server : IP of Server            
  # ======================================================================


Dhcp Server SERVER-IP Scope SCOPE-IP Add reservedip RESERVEVED-IP MAC-ADDRESS "SomePC" "Description" "BOTH"

 

and paste in your own list (from your spreadsheet).

 

then import the amended file with

 

netsh exec c:\dhcp.txt

 

Works a treat for us.

 

HBJB

  • Thanks 3
Posted

@Heebeejeebee & Iain

 

Gents,

 

Thanks for your help, DHCP now a lot more organised!

 

Thanks for your help :D

 

Gonk

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...