Let's say the new DNS servers are 192.168.11.250 and 192.168.11.251
Let's say you have a folder called Myscripts in C:\
You create a file called Server-List.txt that contains all your servers'
names, listed one per line and put it in C:\myscripts
Then you copy the following code, put it in a file and call the file, say,
change-dns.vbs
Off you go.
'Code starts here
Const FILEPATH = "C:\MyScripts\"
'Get the input file
Set FSO = CreateObject("Scripting.FileSystemObject")
Set fsoFile = FSO.GetFile(FILEPATH & "Server-List.txt")
strFilePath = fsoFile.Path
Set fsoInput = FSO.OpenTextFile(strFilePath, 1)
Do While Not fsoInput.AtEndOfStream
ComputerName = fsoInput.ReadLine
Call ChangeDNS_addy(ComputerName)
Loop
Set fsoInput = Nothing
Set fsoFile = Nothing
set FSO=Nothing
Sub ChangeDNS_addy(ComputerName)
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & ComputerName & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled =
True")
For Each objNetCard in colNetCards
arrDNSServers = Array("192.168.11.250", "192.168.11.251")
objNetCard.SetDNSServerSearchOrder(arrDNSServers)
Next
Set colNetCards = Nothing
Set objWMIService = Nothing
End Sub
'code ends
Enjoy.
Sincerely,
Dèjì Akómöláfé, MCSE+M MCSA+M MCP+I
Microsoft MVP - Directory Services
www.readymaids.com - we know IT
www.akomolafe.com
Do you now realize that Today is the Tomorrow you were worried about
Yesterday? -anon
________________________________
From: [EMAIL PROTECTED] on behalf of Tom Kern
Sent: Sat 8/13/2005 4:41 PM
To: [email protected]
Subject: Re: [ActiveDir] ok, last one really
what I really want to do, is modify that script to read all my servers
with static ip's from a text file and change their dns ip's to point
to 2 new dns servers and get rid of the old ones.
we have about 500 servers and they all have static ip's and we're
changing over our dns to 2 new servers.
i'd like to script pointing them to the new servers. either remotely
or from a login script.
the script i sent will do that but you have to enter the server
names/ip's in the script and it prints info to stdout.
i'd rather it read from a text file and only log errors or info to a
seperate file.
is this doable?
thanks a lot!
On 8/12/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
wrote:
> How about
>
> While ts.AtEndOfStream
> strcomputer=ts.readline
> wend
> ts.close
>
> James R. Day
> Active Directory Core Team
> Office of the Chief Information Officer
> National Park Service
> 202-230-2983
> [EMAIL PROTECTED]
>
>
> |---------+---------------------------------->
> | | Tom Kern |
> | | <[EMAIL PROTECTED]> |
> | | Sent by: |
> | | [EMAIL PROTECTED]|
> | | tivedir.org |
> | | |
> | | |
> | | 08/12/2005 04:32 PM AST|
> | | Please respond to |
> | | ActiveDir |
> |---------+---------------------------------->
>
>----------------------------------------------------------------------------
--------------------------------------------------|
> |
|
> | To: [email protected]
|
> | cc: (bcc: James Day/Contractor/NPS)
|
> | Subject: Re: [ActiveDir] ok, last one really
|
>
>----------------------------------------------------------------------------
--------------------------------------------------|
>
>
>
>
> how would you write that to loop thru every line in a file?
>
> thanks
>
> On 8/12/05, Alain Lissoir <[EMAIL PROTECTED]> wrote:
> > On MSDN, you can find some sample scripts to read from a file.
> > See at
> >
>
http://msdn.microsoft.com/library/en-us/script56/html/sgWorkingWithFiles.asp
>
> >
> > For instance,
> >
> > Dim fso, ts
> > Const ForReading = 1
> > Set fso = CreateObject("Scripting. FileSystemObject")
> > Set ts = fso.OpenTextFile("c:\test.txt", ForReading, True)
> > strComputer = ts.ReadLine()
> > ts.Close()
> >
> > Depending on the format of your file, you can read a single line and
> split
> > the comma separated computer names or
> > You can loop and read lines one-by-one if you have a computer name per
> line.
> > Your call ...
> >
> > For a book on scripting and WMI, you can always have a look at my web
> site
> > ;) http://www.lissware.net
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of Tom Kern
> > Sent: Friday, August 12, 2005 7:46 AM
> > To: activedirectory
> > Subject: [ActiveDir] ok, last one really
> >
> > How can i change this script so i can just feed it a file of computer
> names
> > so i can automate the changing of dns servers in the client properties?
> >
> > SCRIPT-
> >
> > On Error Resume Next
> >
> > strComputer = "."
> > arrNewDNSServerSearchOrder = Array("192.168.0.1", "192.168.0.2")
> >
> > Set objWMIService = GetObject("winmgmts:" _ &
> > "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set
> > colNicConfigs = objWMIService.ExecQuery _ ("SELECT * FROM
> > Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
> >
> > WScript.Echo VbCrLf & "Computer: " & strComputer
> >
> > For Each objNicConfig In colNicConfigs
> > WScript.Echo VbCrLf & " Network Adapter " & objNicConfig.Index
> > WScript.Echo " DNS Server Search Order - Before:"
> > If Not IsNull(objNicConfig.DNSServerSearchOrder) Then
> > For Each strDNSServer In objNicConfig.DNSServerSearchOrder
> > WScript.Echo " " & strDNSServer
> > Next
> > End If
> > intSetDNSServers = _
> > objNicConfig.SetDNSServerSearchOrder(arrNewDNSServerSearchOrder)
> > If intSetDNSServers = 0 Then
> > WScript.Echo " Replaced DNS server search order list."
> > Else
> > WScript.Echo " Unable to replace DNS server search order list."
> > End If
> > Next
> >
> > WScript.Echo VbCrLf & String(80, "-")
> >
> > Set colNicConfigs = objWMIService.ExecQuery _ ("SELECT * FROM
> > Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
> >
> > For Each objNicConfig In colNicConfigs
> > WScript.Echo VbCrLf & " Network Adapter " & objNicConfig.Index
> > WScript.Echo " DNS Server Search Order - After:"
> > If Not IsNull(objNicConfig.DNSServerSearchOrder) Then
> > For Each strDNSServer In objNicConfig.DNSServerSearchOrder
> > WScript.Echo " " & strDNSServer
> > Next
> > End If
> > Next
> >
> > END OF SCRIPT
> >
> >
> > also, can anyone recommend a good VBscript book for Windows admining so i
> > can leave you guys alone?
> >
> > thanks
> > List info : http://www.activedir.org/List.aspx
> > List FAQ : http://www.activedir.org/ListFAQ.aspx
> > List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/
> >
> > List info : http://www.activedir.org/List.aspx
> > List FAQ : http://www.activedir.org/ListFAQ.aspx
> > List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/
> >
> List info : http://www.activedir.org/List.aspx
> List FAQ : http://www.activedir.org/ListFAQ.aspx
> List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/
>
>
> List info : http://www.activedir.org/List.aspx
> List FAQ : http://www.activedir.org/ListFAQ.aspx
> List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/
>
List info : http://www.activedir.org/List.aspx
List FAQ : http://www.activedir.org/ListFAQ.aspx
List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/
List info : http://www.activedir.org/List.aspx
List FAQ : http://www.activedir.org/ListFAQ.aspx
List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/