Aussie owned and operated, with 23+ years of industry experience, Gold Coast InfoTech is delighted to support all of your business technology requirements.

Gallery

Contacts

success@goldcoastinfotech.com.au

1800 291 071

KBArticles Scripts, Commands, Registry Uncategorized

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

Author

Customer

Leave a comment

Your email address will not be published. Required fields are marked *