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 :
Can anybody tell me why it doesn't work ?
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 ?