Friday, January 23, 2009

Add Connection Specific dns suffix through command line

There is no direct command available in windows to add connection specific dns suffix for a particylar network connectin. However, one can achieve this by writing windows scripts.

The following snippet will add connection-specific dns suffix to a specific local are network connection. Copy the snippet and save it to a file say setdnssuffix.wsf and run as wscript setdnssuffix.wsf /DNSDomainSuffix:"" on command prompt. here "" is dns suffix need to be added.

You can download the script at SetDnsSuffix
< language="VBScript">
Public DNSDomainSuffix
Set colNamedArguments =WScript•Arguments.Named
DNSDomain = colNamedArguments.Item ("DNSDomainSuffix")
NetConnName = colNamedArguments.Item("netConnName")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapter")
For Each objItem in colItems
If Not IsNull(objItem.NetConnectionID) Then
if objItem.NetConnectionID = NetConnName Then
strMacAddress = objItem.MacAddress
end if
End If
call ExecuteDnsSuffix (WMIEchoStr)
Function ExecuteDnsSuffix(WMIEchoStr)
strComputer = "•"
Set objWMIService = GetObject("winmgmts:"
& "{impersonationLevel=impersonate}!¯\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery –
("Select * From Win32–NetworkAdapterConfiguration Where IPEnabled =True")
For Each objNetCard in colNetCards
End Function


Anonymous said...

This is just what I need

Do you have a way to tick the following boxes as well?

- Register this connection's addresses in DNS

- Use this connection's DNS suffix in DNS registration

Greek said...

netsh interface ipv4 set dnsservers name="Local Area Connection" source=dhcp register=both

Design by infinityskins.blogspot