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!

Need NT script to change a line in a text file on 60+ servers

Status
Not open for further replies.

danfall33

Technical User
Feb 7, 2007
3
US
Hi,

I need to change one line in a text file on 60+ W2k3 servers in the same domain. I have admin rights on all servers and can access all of them from my XP workstation
where I also have the W2K3 resource kit installed. The text files on all the servers are all different so I just can't copy a new file to all of them. Would prefer to use NT script as I'm unfamilar with Pearl or VBscript.
This seems like a simple programming task but the solution escapes me at the moment. Anybody do this before...how?

Thanks,

Dan
 
Thanks,

I'm not sure if I should trust this 3rd party tool.
I'm dealing with some pretty sensitive stuff and
if this thing blows up there will be hell to pay.
I was looking for more of a "native" solution.
Thanks for your help though!!
 
ReplaceEM, would probably work for you. It's a good search & replace program that can work on a single file, multiple files in a folder, or multiple files across multiple locations. I've used it for several years now and never had it mess up any data (unless I told it incorrect changes to make :) You set up a replace group that has the text changes to make, then add files/folders to the replace group for it to process.
 
Is this text file in the same location on all servers? Is the line of text to be change the same in each text file? If true to both, then VBScript would surely be the easiest and most native Windows way to do this. I wouldn't suggest using a third-party tool to do this, as this is clearly a job simply done with VBScript.

If this is a simple string modification in a text file, try posting the question in VBScript forum. I'm sure you'll find much advice on the subject.

I hope you find this post helpful,

Jonathan Almquist
Minneapolis, MN
 
Here is a vbscript I wrote to update INI files that shoudl do the trick for you.

Code:
'==========================================================================
'
' NAME: EditIni.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 
' COPYRIGHT (c) 2007 All Rights Reserved
'
' COMMENT: Replaces a line of text within an INI file.
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED To
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'
'==========================================================================


Const ForReading = 1
Const ForWriting = 2
Const ReadOnly = 1
Dim fso, fsoFile, fsoTextStream, strOldBootIni, strnewBootIni, bToggledReadOnlyAttribute,iniPath


Set fso = CreateObject("Scripting.FileSystemObject")
'Edit this line with the ini Path and file name
iniPath = "C:\Windows\module.ini"

Set fsoFile = fso.GetFile(iniPath)

bToggledReadOnlyAttribute = False
If fsoFile.Attributes And ReadOnly Then
	fsoFile.Attributes = fsoFile.Attributes - ReadOnly
	bToggledReadOnlyAttribute = True
End If


Set fsoTextStream = fso.OpenTextFile(iniPath, ForReading)
strOldBootIni = fsoTextStream.ReadAll
fsoTextStream.Close

'Here is where you specify what the old text is and what the new text is 
'In this example I am changing COMMPOLLSIZE=ON to OFF
strNewBootIni = Replace(strOldBootIni, "COMMPOLLSIZE=On", "COMMPOLLSIZE=Off")


Set fsoTextStream = fso.OpenTextFile(iniPath, ForWriting)
fsoTextStream.Write strNewBootIni
fsoTextStream.Close

If bToggledReadOnlyAttribute = True Then
	fsoFile.Attributes = fsoFile.Attributes + ReadOnly
End If

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top