Page 1 of 1 1
Topic Options
#141303 - 2005-06-08 08:05 PM Static IP TO DHCP conversion script
tmclean Offline
Fresh Scripter

Registered: 2001-01-26
Posts: 18
Loc: Sault Ste. Marie Ontario
At one time, I've seen a script on this forum to perform a conversion from statically IP assigned workstations to DHCP. I cannot find it now. Has anyone else seen it or is it still around. Thx.
Top
#141304 - 2005-06-09 05:39 AM Re: Static IP TO DHCP conversion script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
NETSH should be able to help you out. Otherwise, search the BBS for DHCP in the subject line.
_________________________
There are two types of vessels, submarines and targets.

Top
#141305 - 2005-06-09 10:22 PM Re: Static IP TO DHCP conversion script
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Did this once.
Did a script for it on W2K. I'll post it if I can find it when I’m in the office tomorrow.


Edited by R2D2 (2005-06-09 10:22 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#141306 - 2005-06-10 12:43 AM Re: Static IP TO DHCP conversion script
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
Using these links...
Kixomatic
Enable DHCP
Win32_NetworkAdapterConfiguration

...produced this code...
Code:
 
Break On
$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=-1")

For Each $objNetAdapter In $colItems
$=$objNetAdapter.EnableDHCP
Next



Hope this helps.
_________________________
(... better days ahead)

Top
#141307 - 2005-06-10 01:31 AM Re: Static IP TO DHCP conversion script
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
This probably needs some work but its a start...

Suggestions?

Code:
 
function EnableDHCP(optional $remotepc,optional $adapter)
dim $objWMIService, $colitems, $objnetadapter
$enableDHCP=1
if $remotepc=""
$remotepc="."
endif
$objWMIService = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2")
if @error
exit @error
endif
$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=-1")
For Each $objNetAdapter In $colItems
if $adapter
if substr($objnetadapter.caption,12)=$adapter
$=$objNetAdapter.EnableDHCP
if @error=0
$enableDHCP=0
endif
endif
else
$=$objNetAdapter.EnableDHCP
if @error=0
$enableDHCP=0
endif
endif
Next
endfunction

_________________________
(... better days ahead)

Top
#141308 - 2005-06-10 01:51 AM Re: Static IP TO DHCP conversion script
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
It is not enough to just enable DHCP cuz all the other properties like WINS, DNS, etc, will still be hard coded.

NETSH has an interface reset command that I think will zero those all out.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#141309 - 2005-06-10 02:19 AM Re: Static IP TO DHCP conversion script
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
Code:

$strComputer = "."
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\cimv2")
if $objWMIService
$colNetAdapters = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each $objNetAdapter In $colNetAdapters
$errEnable = $objNetAdapter.EnableDHCP()
? iif($errEnable=0,"Success","Error Setting DHCP")
Next
else
? "error getting WMI"
endif

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#141310 - 2005-06-10 04:07 AM Re: Static IP TO DHCP conversion script
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
Good catch Les... updated...

Code:

function EnableDHCP(optional $remotepc)
dim $objWMIService, $colitems, $objnetadapter,$
$enableDHCP=1
if $remotepc=""
$remotepc="."
endif
$objWMIService = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2")
if @error
exit @error
else
$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=-1")
For Each $objNetAdapter In $colItems
$=$objNetAdapter.EnableDHCP
$=$objNetAdapter.SetDNSServerSearchOrder
$=$objNetAdapter.SetDNSDomain
$=$objNetAdapter.SetWINSServer("","")
$enabledhcp=0
Next
endif
endfunction



Edited by Allen (2005-06-11 11:04 PM)

Top
#141311 - 2005-06-29 01:19 AM Re: Static IP TO DHCP conversion script
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
What if your WINS server is not set by DHCP because you're using a Raptor Firewall that does not allow you to modify the setting.
Top
#141312 - 2005-06-29 01:52 AM Re: Static IP TO DHCP conversion script
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
ROFL...

uh... get another firewall maybe? Your request is so specific... how in the world would you expect me to know that?


I guess the easiest thing to do would be to rem out the line where it modifies the WINS settings.
_________________________
(... better days ahead)

Top
#141313 - 2005-06-29 01:57 AM Re: Static IP TO DHCP conversion script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
indeed...
if your firewall is stupid, don't expect other programs to cover for it.
_________________________
!

download KiXnet

Top
#141314 - 2005-06-29 06:39 PM Re: Static IP TO DHCP conversion script
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
ROFL... Well this article actually goes over this stuff fairly well. Not 100% complete, but not too bad.

Quote:

This paper discusses scripting techniques and shows scripting examples that enable system administrators to automate many common tasks involved in managing TCP/IP network clients.






Automating TCP/IP Networking on Clients
 
Online version

Automating TCP/IP Networking on Clients - Online version
 

Top
#141315 - 2005-08-04 03:04 AM Re: Static IP TO DHCP conversion script
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
@Doc
Quote:

What if your WINS server is not set by DHCP because you're using a Raptor Firewall that does not allow you to modify the setting.




I incorporated the EnableDHCP and SetStaticIPOptions UDF into one: SetIPOptions()

Still hoping you upgraded that piece of .... but the new UDF should allow you do what you were asking for.
_________________________
(... better days ahead)

Top
#141316 - 2005-08-04 10:18 AM Re: Static IP TO DHCP conversion script
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Thanks Al, but not for 2000 clients. The DNS settings I want to change are not supported by WMI on 2000 only on XP/2003

Yeah, we have a new Cisco 4507 and have 6 servers on order soon to bring up our own DHCP Server to set this crap.
 

Top
#141317 - 2005-08-04 03:31 PM Re: Static IP TO DHCP conversion script
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I think NetSH could do it on W2K. 6 servers to bring up DHCP?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#141318 - 2005-08-04 06:52 PM Re: Static IP TO DHCP conversion script
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
LOL, no not just for DHCP - For new AD structure.

As for NetSH I'm not sure what the requirements are but remote machines I tested came back with error msgs. Not a big deal, will wait for DHCP

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.121 seconds in which 0.037 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org