×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

modifying dns client configuration on windows 2003

modifying dns client configuration on windows 2003

modifying dns client configuration on windows 2003

(OP)
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 --> vbscript

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 ?

RE: modifying dns client configuration on windows 2003

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"?

RE: modifying dns client configuration on windows 2003

(OP)
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 

RE: modifying dns client configuration on windows 2003

Ok, step one: comment out the evil 'On Error Resume Next'

RE: modifying dns client configuration on windows 2003

(OP)
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.

RE: modifying dns client configuration on windows 2003

smile

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close