Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

modifying dns client configuration on windows 2003

Status
Not open for further replies.

cborivant

Technical User
May 13, 2005
18
FR
Hello,

I need to change the dns configuration on more than 200 servers. Each server is its own dns server.
I wrote a VB script that seems to do the jobs but it does nothing.
Of course I did a lot of research on google but can not find whet the problem can be with my script.
so here is my script :
Code:
on error resume next

Set args  = Wscript.Arguments

dim DNS ()
dim SearchDomains ()
DNS(0)=args(0)
SearchDomains(0)="mab.local"

strComputer = "."

Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\CIMV2") 

Set colObjets = objWMI.ExecQuery("SELECT * FROM Win32_NetworkAdapter where NetConnectionID> ''")

For Each objet in colObjets 

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled=True and MACAddress='" & objet.MACAddress & "'",,48)

    For Each objItem in colItems
        For Each adresse in objItem.IPAddress
    
          if adresse=args(0) then
            
            code=objItem.EnableDNS(,,DNS,SearchDomains)
            if code=0 Then
              msg="configuration dns activée"
            Else
              msg=msg & "Erreur d'activation de la configuration dns"
            End If
            wscript.echo msg

            code=objItem.SetDNSServerSearchOrder(DNS)
            if code=0 Then
              msg="DNS affecté(s) à " & args(0) & " avec succès"
            Else
              msg=msg & "Erreur d'affectation de DNS à " & args(0) & " (code " & code & ")"
            End If
            wscript.echo msg

            code=objItem.SetDNSSuffixSearchOrder(SearchDomains)
            if code=0 Then
              msg="suffix de recherche affecté(s) à " & args(0) & " avec succès"
            Else
              msg=msg & "Erreur d'affectation de suddix de recherche à " & args(0) & " (code " & code & ")"
            End If
            wscript.echo msg

          End If
        Next
    Next
Next

Can anybody tell me why it doesn't work ?
 
Perhaps you could help us to help you by being a bit more explicit about "does nothing". Runs without error, but no DNS changes? Runs with errors? Are you seeing the messages you expect if it were working, e.g. "configuration dns activée"?

 
By nothing I mean, nothing is done on the configuration but the script displays the messages as if everything went ok. So the script seems to have no effects.
Here is the output of the script :
Code:
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. Tous droits réservés.

configuration dns activée
DNS affecté(s) à 192.168.0.134 avec succès
suffix de recherche affecté(s) à 192.168.0.134 avec succès
 
Thanks a lot !

I'm really not used to windows scripting. I think I know what happens now !
Thanks for your help, I'm on the right direction now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top