jadewith
(Fresh Scripter)
2006-11-30 08:30 PM
Change DNS suffix search order

Hello everyone,

I am trying to Change DNS Suffix search order to accomodate our new(meaning very first) DNS name spaces. I found a VB script that does what I need but would like to convert it to KiXtart and have had no luck.

Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
$strHostName = ""
arrDNSSuffixes = Array("crappy.com,silly.net")
objNetworkSettings.EnableDNS strHostName, , , arrDNSSuffixes	


I have figurred out this part from poking around the board, but haven't been able to pull the trigger.

Code:
$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2")

$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=-1")
strHostName = ""

For each $objNetworkSettings in $colItems
     $dnssuffix=$objNetworkSettings.DNSDomainSuffixSearchOrder("crappy.com,silly.net")

Next



Thanks for any help


AllenAdministrator
(KiX Supporter)
2006-11-30 11:36 PM
Re: Change DNS suffix search order

See SetIPOptions()

jadewith
(Fresh Scripter)
2006-12-01 12:10 AM
Re: Change DNS suffix search order

Hi Allen,

I've looked at your udf and it doesn't have a Dns Suffix Search order setting. I tried adding it myself:

Code:
case $setting="DNSSearchSuffixes"
          $settings[0]='SetDNSDomainSuffixSearchOrder($value)'


but even if it didn't give me the error "expected ')' Line 153", it would only be good for one domain right? and I've got at least 3 to enter. Is SetDNSDomainSuffixSearchOrder even a valid wmi command?


Skip
(Fresh Scripter)
2006-12-01 12:44 AM
Re: Change DNS suffix search order

Here is what we had to use for a while. We had this script called from within another script and it worked pretty well

Code:
SetConsole ("ALWAYSONTOP")
If @PRODUCTTYPE = "Windows XP Professional" or @PRODUCTTYPE="Windows 2000 Professional"
Else 
	RETURN
EndIf
$SearchValue = ReadValue("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters","SearchList")
	If $SearchValue = "domain1.corp.com,domain2.corp.com,corp.com"
		RETURN
	EndIf

$SEARCHLIST="HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\"
WriteValue($SEARCHLIST, "Searchlist", "domain1.corp.com,domain2.corp.com,corp.com", "REG_SZ")
RETURN


jadewith
(Fresh Scripter)
2006-12-01 01:10 AM
Re: Change DNS suffix search order

Thanks Skip,

I found something similar earlier today, and it wrote the entry just fine, only the card wouldn't use the suffixes listed. Yours works fine though, so go figure.

I would prefer to make the change via wmi but beggers can't be choosers. I think the reason that the wmi command wasn't working (other than that I'm only a mediocre script writer) comes from microsmurf:


DNSDomainSuffixSearchOrder
String
Space-delimited list of DNS domain suffixes to be appended to the end of host names during name resolution. When attempting to resolve a fully-qualified domain name (FQDN) from a host only name, the system will first append the local domain name. If this is not successful, the system will use the domain suffix list to create additional FQDNs in the order listed and query DNS servers for each

Example: "samples.microsoft.com example.microsoft.com"


And I don't know how to set a "space delimited" array.


AllenAdministrator
(KiX Supporter)
2006-12-01 02:46 AM
Re: Change DNS suffix search order

My apologies... yes you are right, SetIPOptions will not work for that.

jadewith
(Fresh Scripter)
2006-12-01 04:33 AM
Re: Change DNS suffix search order

Does this mean that setting the DNSDomainSuffixSearchOrder cannot be done through WMI with KiXtart? If so "THANK GOD!", that means I'm not as bad as I thought (of course I'm back to even because I didn't know that when I started). If anyone has any idea how to do this through WMI I'd love to hear it, otherwise thank you all for your help.

Jason


AllenAdministrator
(KiX Supporter)
2006-12-01 06:15 AM
Re: Change DNS suffix search order

At least for win32_networkadapterconfiguration DNSDomainSuffixSearchOrder is readonly.

http://msdn.microsoft.com/library/defaul...nfiguration.asp
Quote:
DNSDomainSuffixSearchOrder
Data type: string array
Access type: Read-only

Array of DNS domain suffixes to be appended to the end of host names during name resolution. When attempting to resolve a fully-qualified domain name (FQDN) from a host only name, the system will first append the local domain name. If this is not successful, the system will use the domain suffix list to create additional FQDNs in the order listed and query DNS servers for each.

Example: "samples.microsoft.com example.microsoft.com"


SetDNSDomainSuffixSearchOrder seems to be NT only.
http://msdn.microsoft.com/library/defaul...nfiguration.asp

As for your example code, I think (and I would appreciate our COM Gurus to speak up) this is one of those settings that kixtart does not properly handle.

There may be another way, but at least you have the reg hack.


Chris S.
(MM club member)
2006-12-04 06:03 AM
Re: Change DNS suffix search order

This seemed to work for me...

Code:
$strComputer = "."
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\cimv2")
 
$objNetworkSettings = $objWMIService.Get("Win32_NetworkAdapterConfiguration")
$strHostName = ""
$arrDNSSuffixes = Split("crappy.com,silly.net",",")
 
$rc = $objNetworkSettings.EnableDNS($strHostName, , , $arrDNSSuffixes)
@SERROR ?


NTDOCAdministrator
(KiX Master)
2006-12-04 08:19 AM
Re: Change DNS suffix search order

Do I see another update coming for Al's UDF

AllenAdministrator
(KiX Supporter)
2006-12-05 04:13 AM
Re: Change DNS suffix search order

Well, I considered it. Problem is, SetIPOptions is sort of designed to target specific adapters, where as this DNSServerSuffixOrder thingy applies to all adapters. I need to play with it more, and see if I can incorporate it without causing an issues.