Change windows server DNS Search suffix
The below script will find the adapter called “Local Area Connection” and give is a dnssearchsuffix of mydomainname.com
‘Change the Computers DNS Search Suffix
DNSDomain = “mydomainname.com”
NetConnName = “Local Area Connection”
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\” & strComputer & “rootcimv2”)
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
Next
call ExecuteDnsSuffix(WMIEchoStr)
Function ExecuteDnsSuffix(WMIEchoStr)
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\” & strComputer & “rootcimv2”)
Set colNetCards = objWMIService.ExecQuery _
(“Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True”)
For Each objNetCard in colNetCards
if strMacAddress = objNetCard.MacAddress then
ExecuteDnsSuffix=objNetCard.SetDNSDomain(DNSDomain)
end if
Next
WMIEchoStr=DNSDomain
End Function
‘