Re: All DHCP Servers Info HELP!
- From: mlindsey@xxxxxxxxxxx
- Date: 20 Nov 2006 13:50:34 -0800
So does this look correct to you? The Name of my PC is Megaslowtron.
logfile and output is just any folder I create locally correct?
Then all I do is run it as a bat file locally on my machine right?
Thanks again for your help.
'==================================================
' Run DHCP EXP
'==================================================
set oFs = createobject("scripting.filesystemobject")
set shell = createobject("wscript.shell")
set net = createobject("wscript.network")
'on error resume next
datafile = "\\megaslowtron\DHCP\DCs.txt"
logfile = "C:\DHCP\Ex-DHCP-Log.txt"
output = "C:\DHCP\"
set svrlist = oFs.opentextfile(datafile, 1)
set exlog = oFs.createtextfile(logfile)
dim svr, svrIP,ProcID
'==================================================
function ex()
Set objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\"
& svr & "\root\cimv2:Win32_Process")
errReturn = objWMIService.Create("cmd.exe /c netsh dhcp dump >
C:\Temp\" &
UCASE(svr) & "-DHCP.cfg", null, null, procID)
Set objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\"
& svr & "\root\cimv2")
iLoop = 0
PrcRun = 1
Do until PrcRun = 0 or iLoop = 5
Set colProcesses = objWMIService.ExecQuery("SELECT * FROM
Win32_Process
WHERE ProcessID = '" & ProcID & "'")
iLoop = iLoop + 1
PrcRun = colProcesses.Count
wscript.sleep 1000
Loop
oFs.copyfile "\\" & svr & "\c$\Temp\" & UCASE(svr) & "-DHCP.cfg",
"C:\DHCP\"
'==================================================
set dhcpcfg = ofs.opentextfile(output & UCASE(svr) & "-DHCP.cfg")
txt = dhcpcfg.readall
dhcpcfg.close
set oReg = new RegExp
oreg.global = true
oreg.IgnoreCase = true
oreg.Pattern = svrIP
txt = oreg.replace(txt, " 127.0.0.1")
set dhcpcfg = ofs.createtextfile(output & UCASE(svr) & "-DHCP.cfg")
dhcpcfg.writeline txt
dhcpcfg.close
end function
'==================================================
Do until svrlist.atendofstream
svrsrc = SPLIT(svrlist.readline, ",")
svr = svrsrc(0)
svrIP = svrsrc(1)
set pingpc = shell.exec("ping -n 2 " & svr)
pingstatus = lcase(pingpc.stdout.readall)
If instr(pingstatus, "reply") Then
call ex()
exlog.writeline svr & " is up - starting DHCP-EX - " & now()
Else
exlog.writeline svr & " is down - !!FAILED!! to start DHCP-EX -
" & now()
End If
Loop
'==================================================
' End Script
'==================================================
Adam Wylie wrote:
Hey mate, heres a script i wrote to export some config from our DHCP servers.
Hope it helps.
Just edit the variables up the top.
the "datafile" variable should be the path to a text file with each of your
DHCP server names on each line.
We schedule this export task and use it as part of a DR process as you can
use NETSH exec to load up the config on another box.
'==================================================
' Run DHCP EXP
'==================================================
set oFs = createobject("scripting.filesystemobject")
set shell = createobject("wscript.shell")
set net = createobject("wscript.network")
'on error resume next
datafile = "\\bath-fs01\users$\awylie\Monitoring\DCs.txt"
logfile = "D:\Web\Svrmgmt\DHCP\Ex-DHCP-Log.txt"
output = "D:\Web\Svrmgmt\DHCP\"
set svrlist = oFs.opentextfile(datafile, 1)
set exlog = oFs.createtextfile(logfile)
dim svr, svrIP,ProcID
'==================================================
function ex()
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"
& svr & "\root\cimv2:Win32_Process")
errReturn = objWMIService.Create("cmd.exe /c netsh dhcp dump > C:\Temp\" &
UCASE(svr) & "-DHCP.cfg", null, null, procID)
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"
& svr & "\root\cimv2")
iLoop = 0
PrcRun = 1
Do until PrcRun = 0 or iLoop = 5
Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process
WHERE ProcessID = '" & ProcID & "'")
iLoop = iLoop + 1
PrcRun = colProcesses.Count
wscript.sleep 1000
Loop
oFs.copyfile "\\" & svr & "\c$\Temp\" & UCASE(svr) & "-DHCP.cfg",
"D:\Web\Svrmgmt\DHCP\"
'==================================================
set dhcpcfg = ofs.opentextfile(output & UCASE(svr) & "-DHCP.cfg")
txt = dhcpcfg.readall
dhcpcfg.close
set oReg = new RegExp
oreg.global = true
oreg.IgnoreCase = true
oreg.Pattern = svrIP
txt = oreg.replace(txt, " 127.0.0.1")
set dhcpcfg = ofs.createtextfile(output & UCASE(svr) & "-DHCP.cfg")
dhcpcfg.writeline txt
dhcpcfg.close
end function
'==================================================
Do until svrlist.atendofstream
svrsrc = SPLIT(svrlist.readline, ",")
svr = svrsrc(0)
svrIP = svrsrc(1)
set pingpc = shell.exec("ping -n 2 " & svr)
pingstatus = lcase(pingpc.stdout.readall)
If instr(pingstatus, "reply") Then
call ex()
exlog.writeline svr & " is up - starting DHCP-EX - " & now()
Else
exlog.writeline svr & " is down - !!FAILED!! to start DHCP-EX - " & now()
End If
Loop
'==================================================
' End Script
'==================================================
"mlindsey@xxxxxxxxxxx" wrote:
I have a list of all my DHCP servers but need to get all the info about
each. I need to get their scopes/reservations/etc. Is there something
out there that will tell me this info about all my DHCP server on my
network?
.
- Follow-Ups:
- Re: All DHCP Servers Info HELP!
- From: mlindsey
- Re: All DHCP Servers Info HELP!
- References:
- All DHCP Servers Info HELP!
- From: mlindsey
- RE: All DHCP Servers Info HELP!
- From: Adam Wylie
- All DHCP Servers Info HELP!
- Prev by Date: Re: ADPREP /forestprep And R2
- Next by Date: Re: Help with LDAP PagedSearch
- Previous by thread: RE: All DHCP Servers Info HELP!
- Next by thread: Re: All DHCP Servers Info HELP!
- Index(es):