|
|
Question : Modify vbs script for appending
|
|
Hi All,
I reall y need help with this!!
I have a script that checks which automatic services are running on servers after a reboot and outputs to a csv file. The script checks the servers from a tx file. This script does this with no problems. What i want to do is modify the script slightly so that the script will be copied onto each server (we can do this manually so i don't need this scripted, but do get rid of the part of the script which references the txt file) and when the server reboots the script will run automatically (using startup shortcut) and forward it's results to a central location on the network. there are 450 servers in total so each result will need to add a new line to the central csv/txt file rather than overwriting the first line all the time. e.g. servername checked ok date time servername checked not ok date time alerter serveice stopped etc.....
See the script below. Thanks All.
Option Explicit
Const COMPUTER_LIST = "Computers.txt"
Dim objFileSystem, objFile, objStream, objWMIService, objItem Dim strComputer, strMessage, tmpMsg Dim colServices
Set objFileSystem = CreateObject("Scripting.FileSystemObject") Set objFile = objFileSystem.GetFile(COMPUTER_LIST) Set objStream = objFile.OpenAsTextStream(1, 0)
Do While Not objStream.AtEndOfStream strComputer = objStream.ReadLine If strComputer <> "" Then On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer)
if err.number <> 0 then strMessage = strMessage & strComputer & ",Not Reachable" & VbCrLf else Set colServices = objWMIService.InstancesOf("Win32_Service")
strMessage = strMessage & strComputer
tmpMsg = "" For Each objItem In colServices If objItem.StartMode = "Auto" Then If objItem.State <> "Running" Then tmpMsg = tmpMsg & "," & objItem.DisplayName & "," & objItem.State End If End If Next
if tmpMsg = "" then strMessage = strMessage & ",Checked,Ok," & Date & ":" & Time else strMessage = strMessage & ",Checked,Not Ok," & Date & ":" & Time & tmpMsg end if
strMessage = strMessage & VbCrLf Set colServices = Nothing
end if
Set objWMIService = Nothing End If Loop
Set objStream = Nothing Set objFile = Nothing
Set objFile = objFileSystem.OpenTextFile("Report.csv", 2, True, 0)
objFile.WriteLine strMessage
Set objFile = Nothing Set objFileSystem = Nothing
|
Answer : Modify vbs script for appending
|
|
If you have problems with this line: >> Set objWMIService = GetObject("winmgmts:\\127.0.0.1")
Change it to: >> Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Regards, Dez
|
|
|
|
|