Configure Network Controller

(imported topic written by boostaz191)

I need to turn on DHCP and Set the DNS Server Search Order on client in our network. I have the following script which will do it via VBScript. My question is can it be done in BES? if so How?

strComputer = “.”

Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\” & strComputer & “\root\cimv2”)

Set colNetAdapters = objWMIService.ExecQuery(“Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE”)

For Each objNetAdapter In colNetAdapters

errEnable = objNetAdapter.EnableDHCP()

errEnable = objnetadapter.setdnsserversearchorder()

Next

(imported comment written by SystemAdmin)

Since you already have a solution, you just need to turn it into an action using appendfile.

An action something like this…

delete __appendfile

appendfile strComputer = “.”

appendfile Set objWMIService = GetObject(“winmgmts:{{impersonationLevel=impersonate}!\” & {computer name} & “\root\cimv2”)

appendfile

appendfile Set colNetAdapters = objWMIService.ExecQuery(“Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE”)

appendfile

appendfile For Each objNetAdapter In colNetAdapters

appendfile errEnable = objNetAdapter.EnableDHCP()

appendfile errEnable = objnetadapter.setdnsserversearchorder()

appendfile Next

appendfile

move __appendfile enable-dhcp.vbs

waithidden “{pathname of system folder}\wscript.exe” enable-dhcp.vbs

delete enable-dhcp.vbs

(imported comment written by boostaz191)

Paul,

Thanks, I knew I could do that I had hoped however that it could be done using the “of Networks” option native to bes.

(imported comment written by boostaz191)

Completed delete __appendfile

Completed appendfile On Error Resume Next

Completed appendfile strComputer = “.”

Failed appendfile Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\” & {computer name} & “\root\cimv2”)

appendfile

appendfile Set colNetAdapters = objWMIService.ExecQuery(“Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE”)

appendfile

appendfile For Each objNetAdapter In colNetAdapters

appendfile errEnable = objNetAdapter.EnableDHCP()

appendfile errEnable = objnetadapter.setdnsserversearchorder()

appendfile Next

appendfile

move __appendfile enable-dhcp.vbs

waithidden “{pathname of system folder}\wscript.exe” enable-dhcp.vbs

delete enable-dhcp.vbs

(imported comment written by SystemAdmin)

I think your thinking more about relevance than actions. Relevance can’t modify anything, it only inspects. In an action the only other way to do it would be to modify the registry directly, or download a utility to do it. In my opinion, you have the right answer.

I threw my previous post together really fast, so I didn’t notice my error. Try this instead. You might be able to get away with using “localhost” since it’s executing on the local pc.

-Paul

delete __appendfile

appendfile strComputer = “.”

appendfile Set objWMIService = GetObject(“winmgmts:{{impersonationLevel=impersonate}!\localhost\root\cimv2”)

appendfile

appendfile Set colNetAdapters = objWMIService.ExecQuery(“Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE”)

appendfile

appendfile For Each objNetAdapter In colNetAdapters

appendfile errEnable = objNetAdapter.EnableDHCP()

appendfile errEnable = objnetadapter.setdnsserversearchorder()

appendfile Next

appendfile

move __appendfile enable-dhcp.vbs

waithidden “{pathname of system folder}\wscript.exe” enable-dhcp.vbs

delete enable-dhcp.vbs

(imported comment written by brolly3391)

boostaz1,

The line your action is failing on has a { in it. The curly brackets are a key symbol for Action script to designate relevance substitution.

If you need a { natively, the easiest way is to escape that character by doubling up on it.

appendfile Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\” & {computer name} & “\root\cimv2”)

should read

appendfile Set objWMIService = GetObject(“winmgmts:{{impersonationLevel=impersonate}!\” & {computer name} & “\root\cimv2”)

Note that you do not double the trailing }. Also note that the subsequent relevance substituion {computer name} still works as expected.

Cheers,

Brolly

(imported comment written by tscott91)

So can someone post the full action script to change a PC from static to DHCP and the relevance to go along with it? I have to move over a ton of PC’s to DHCP this weekend and was hoping to use BigFix to do that.

Thanks much!

Tom

(imported comment written by NoahSalzman)

Well, the

googles sayeth

:

netsh interface ip set address “Local Area Connection” dhcp

and for dynamically obtaining DNS settings

netsh interface ip set dns “Local Area Connection” dhcp

So, just throw those in an ActionScript with waithidden in front? Your homework assignment would be A) make sure that command line works on the target OSes you are interested in, B) use relevance to only target boxes that are not set for DHCP, and C) test it out on a small number boxes first to make sure nothing goes wrong.