Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to add two lines to text files using group policy. I cannot replace the files with the updated one since the content of the files differs from one machine to another, but all of them have to be updated with the two new lines. Is it possible to do that?

I already know how to replace a file using a VBScript, then applying it through group policy.

Thanks, Abdullah

share|improve this question

2 Answers 2

This vbscript gives you an idea of what it should look like. They key is to open the files for appending, not for writing. This will just add two lines to the bottom of the text files regardless of their content.

Const ForAppending = 8

strFile1 = "c:\Temp\file1.txt"
strFile2 = "c:\Temp\file2.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile1, ForAppending)

objFile.WriteLine "New Text to add 1"
objFile.WriteLine "New Text to add 2"

objFile.Close

Set objFile = objFSO.OpenTextFile(strFile2, ForAppending)

objFile.WriteLine "New Text to add 1"
objFile.WriteLine "New Text to add 2"

objFile.Close
share|improve this answer

You can also just use batch files to do it as well. echo "Add this line to the end of the file." >> \\path\to\file.txt or whatever. Just do not use the single redirection operation > instead of >, or you will be sorry.

share|improve this answer
    
That is to say the redirect operator > opens for write (clobber) as opposed to >> which opens for append. –  jscott Jul 21 '10 at 18:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.