I am trying to update a file on a bunch of systems with a vbscript, the script finds the severs but it deletes the contents of the file, I read in the file, close it then write to it but it appears the write is not happening.
'====================
'
' Type: VBScript
'
' NAME: TSMFix.vbs
'
' AUTHOR: Bob Smith
'
' PURPOSE: This script will parse a list of servers, and modify the TSM
' config. It requires servers.txt in the same folder as this script.
' Servers.txt should contain one machine name per line.
'
' COMMENTS:
'
' **************************
**********
**********
*******
' ~~~Begin Script~~~
Option Explicit
' Declare Everything!
Dim objFSO, objTextFile, objTextFile1, objTextFile2, objWMIService, objItem, objService, objChksrv, i
Dim strComputer, Line, strNextLine, Srvpad, colItems, colListOfServices, oDrives, WshNetwork
Dim drive, objShell
On Error Resume Next
Const ForReading = 1, ForWriting = 2
Set objFSO = CreateObject("Scripting.Fi
leSystemOb
ject")
' Opens the servers.txt file to find the server name(s)
' --------------------------
----------
----------
-------
Set objTextFile = objFSO.OpenTextFile("C:\Ts
mFix\serve
rs.txt", ForReading)
Set WshNetwork = WScript.CreateObject("WScr
ipt.Networ
k")
Set oDrives = WshNetwork.EnumNetworkDriv
es
Set objShell = WScript.CreateObject("WScr
ipt.Shell"
)
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.Readline
'Check if the Server is online and has TSM folder
' --------------------------
----------
----------
-------
Srvpad = "\\"&strComputer&"\c$\prog
ram files\TIVOLI\TSM\baclient"
IF objFSO.FolderExists(Srvpad
) = FALSE THEN
WScript.Echo "Server " & strServer & " doesn't have TSM or is offline!"
WScript.Quit
END If
' Backup current TSM config
objFSO.CopyFile Srvpad & "\dsm.opt" , Srvpad &"\dsm.opt.old"
' Wait for copy to complete
WScript.Sleep 10000
' Set TSM Service name
' --------------------------
----------
----------
-------
Set objService = GetObject("WinMgmts:{imper
sonationLe
vel=impers
onate}!//"
_
& strComputer & "/root/cimv2:Win32_Service
.Name='TSM
Scheduler'")
' Stop TSM Scheduler
' --------------------------
----------
----------
-------
objService.StopService
' Set the file for Reading / Writing
' --------------------------
----------
----------
-------
Set objTextFile2 = objFSO.OpenTextFile(Srvpad
& "\dsm.opt", ForReading)
strText = objTextFile2.ReadAll
objTextFile2.Close
strNewText = Replace(strText, "HYDRA1", "James")
Set objTextFile2 = objFSO.OpenTextFile(Srvpad
& "\dsm.opt", ForWriting)
objTextFile2.WriteLine strNewText
objTextFile2.Close
' --------------------------
----------
----------
-------
' Wait 10 seconds for things to settle down
WScript.Sleep 10000
' Start TSM Scheduler
objService.StartService
Wscript.Echo "The TSM Scheduler service on " & strComputer & " has restarted succesfully."
' Go get next computer name and start over...
Loop
objTextFile.Close
' --------------------------
----------
----------
-------
' Functions
' --------------------------
----------
----------
-------
'Read text file
Function GetFile(FileName)
If FileName<>"" Then
Dim FS, FileStream
Set FS = CreateObject("Scripting.Fi
leSystemOb
ject")
on Error resume Next
Set FileStream = FS.OpenTextFile(FileName)
GetFile = FileStream.ReadAll
End If
End Function
'Write text file.
Function WriteFile(FileName, Contents)
Dim OutStream, FS
on Error Resume Next
Set FS = CreateObject("Scripting.Fi
leSystemOb
ject")
Set OutStream = FS.OpenTextFile(FileName, 2, True)
OutStream.Write Contents
End Function