Ok i am very new to vbs, im not sure if you guys will be able to help me or not but here it goes. My Boss wants me to come up with a script that allows him to take Event Logs from all different servers and combine them into one file.. I did a search and was able to find something pretty much exactly what i was looking for :
<?XML version="1.0"?>
<package>
<job id="Default">
<script language="jscript">
<![CDATA[
function GetUTCInfo() {
var d, s;
d = new Date();
s = d.getUTCFullYear()+"";
s += PadZero(d.getUTCMonth()+1)+"" ;
s += PadZero(d.getUTCDate())+"";
s += PadZero(d.getUTCHours())+ "";
s += PadZero(d.getUTCMinutes())+ "";
s += PadZero(d.getUTCSeconds())+ "";
return(s)
}
function PadZero(intDay) {
if (intDay < 10)
return (0 + "" + intDay);
else
return (intDay);
}
</script>
<script language="VBScript">
<![CDATA[
Dim strComputerName,objWshNetwork,strDateStamp, arrHosts, i
Dim strOpPath, cstrQ, cstrQCQ, s, Counter, intTime
CONST ForReading = 1, ForWriting = 2, ForAppending = 8
'********************************************************************
'Change the values in this section to reflect your local '*
'environment. '*
'********************************************************************
CONST SLAHosts = "EventHosts.txt" '*
CONST ErrLog = "Error.log" '*
CONST ScriptLog = "EventLog.log" '*
'********************************************************************
Public LogFile
Public ErrorFile
Public objFSO
strOpPath = ExecutingFrom
CheckScriptHost
s=GetUTCInfo(s)
Counter=0
'This is thousandths of a second
intTime=3000
Set objFSO = CreateObject("scripting.FileSystemObject")
arrHosts = HostsToMonitor (strOpPath & SLAHosts,";")
For i=0 to UBound(arrHosts)
'What time is it now? Recalc the value of s
s=GetUTCInfo(s)
'You get a unique error file for each UTC day
ErrorFile = strOpPath & Left(s,8) & ErrLog
If strOpPath <> "" Then
LogFile = strOpPath & Left(s,8) & ScriptLog
Else
LogFile = strOpPath & Left(s,8) & ScriptLog
End if
If Not IsEmpty(arrHosts(i)) Then
wscript.echo arrHosts(i) & " " & Left(s,12)
LogAction "Monitoring " & arrHosts(i)
AsynchEvents(arrHosts(i))
End If
Next
strHeader = "[ Date & Time ] --, Record Number, LogFile, " & _
"Event Identifier, Event Code, Source Name, Type, Category, " & _
"User, ComputerName, Message" ', Insertion Strings, Data"
LogAction strHeader
'wait for however long intTime is before starting this loop
'again
'Counter is a variable that will not be set to 1
'thus we loop until physically interrupted (Ctrl-C)
Do Until Counter=1
wscript.sleep(intTime)
s=GetUTCInfo(s)
If strOpPath <> "" Then
LogFile = strOpPath & Left(s,8) & ScriptLog
Else
LogFile = strOpPath & Left(s,8) & ScriptLog
End if
If NOT objFSO.FileExists(LogFile) Then
LogAction(strHeader)
End If
If Counter=1 Then
Exit Do
End if
Loop
'====================================================================
Sub SINK_OnObjectReady(objObject, objAsyncContext)
WScript.Echo (objObject.TargetInstance.ComputerName) & ", " & _
(objObject.TargetInstance.Message)
strLogEntry=(objObject.TargetInstance.RecordNumber) & ", " & _
(objObject.TargetInstance.LogFile) & ", " & _
(objObject.TargetInstance.EventIdentifier) & ", " & _
(objObject.TargetInstance.EventCode) & ", " & _
(objObject.TargetInstance.SourceName) & ", " & _
(objObject.TargetInstance.Type) & ", " & _
(objObject.TargetInstance.Category) & ", " & _
(objObject.TargetInstance.User) & ", " & _
(objObject.TargetInstance.ComputerName) & ", " & _
(objObject.TargetInstance.Message)
LogAction strLogEntry
End Sub
'====================================================================
Sub AsynchEvents(strComputer)
On Error Resume Next
Set services = GetObject("WinMgmts:{impersonationLevel=impersonate, (security)}!\\" & _
strComputer)
If Err <> 0 Then
LogAction "Setting Remote Event Log Monitoring on " & strComputer & _
" failed. Error Number: " & Err.Number & ", Error Description: " & _
Err.Description
Err.Clear
Exit Sub
End If
Set sink = WScript.CreateObject("WbemScripting.SWbemSink","SINK_")
services.ExecNotificationQueryAsync sink, _
"select * from __instancecreationevent where targetinstance isa 'Win32_NTLogEvent'"
On Error GoTo 0
End Sub
'====================================================================
Sub LogAction (strEntry)
Dim strErrMsg, f
On Error Resume Next
set f = objFSO.OpenTextFile(LogFile, ForAppending, True, -2)
f.WriteLine "[" & Now() & "] -- " & strEntry
If Err <> 0 Then
'write to error log
set f = objFSO.OpenTextFile(ErrorFile, ForAppending, True, -2)
strErrMsg="Could not write to LogFile. " & Err.Number & " " & _
err.Description & ". Attempting to write: " & strEntry
f.WriteLine strErrMsg
End if
wscript.echo "Error Occurred: " & strErrMsg
err.clear
End If
f.close
On Error Goto 0
End Sub
'====================================================================
Function SurveyHost()
Dim strComputer, objWshNetwork
If(WScript.Arguments.Count) Then
strComputer = WScript.Arguments.Item(0)
Else
Set objWshNetwork = WScript.CreateObject("WScript.Network")
strComputer = objWshNetwork.ComputerName
Set objWshNetwork = Nothing
End If
SurveyHost=strComputer
End Function
'====================================================================
Function ErrorLogName()
ErrorLogname=ExecutingFrom & Left(s,8) & ErrLog
End Function
'=======================================================
Function HostsToMonitor(HostSource, strComment)
Dim ts,tsLine,arrLines
On Error Resume Next
Redim arrLines(0)
Set ts=objFSO.OpenTextFile(HostSource,ForReading,False)
If Err <> 0 Then
'SurveyHost function identifies host to monitor
arrLines(0)=SurveyHost
HostsToMonitor=arrLines
Err.Clear
Exit Function
End If
Do While NOT ts.AtEndOfStream
tsLine = Trim(ts.ReadLine)
If tsLine <> "" AND (Left(tsLine,1) <> strComment) Then
Boundary=UBound(arrLines)
Redim Preserve arrLines(Boundary +1)
arrLines(Boundary)=tsLine
End If
Loop
ts.Close
HostsToMonitor=arrLines
End Function
'=======================================================
Function ExecutingFrom()
Dim strScriptPath
strScriptPath=Left(wscript.scriptfullname, _
Len(wscript.scriptfullname)-Len(wscript.scriptname))
If Right(strScriptPath,1) <> "\" Then
strScriptPath=strScriptPath & "\"
End If
ExecutingFrom=strScriptPath
End Function
'====================================================================
Sub CheckScriptHost()
If InStr(LCase(wscript.fullname),"cscript") = 0 Then
strMsg = "Script must be run by CScript.exe. Terminating this " & _
"script, changing the default script engine and restarting" & _
" execution."
Dim objShell
Set objShell=CreateObject("wscript.shell")
strExec = "cscript.exe //NoLogo //H:cscript //S"
objShell.Run strExec,0,TRUE
strExec ="cscript.exe " & Chr(34) & _
wscript.scriptfullname & Chr(34)'& " " & _
' Chr(34) & strArg & Chr(34) & Chr(34)
objShell.Run strExec,,False
Wscript.Quit
End If
End Sub
'====================================================================
]]>
</script>
</job>
</package>
Now this is the part where I am a total n00b at scripting, I am pretty good with VB6 but with scripting I do not understand what I would save this as (I typed this all up in NotePad), like what type of extension, and then where i would run it and where I would look to get its information. I know this has VBScript and some JScript together, but I am hoping that someone still can help me. If there are any further questions you have about my problem just ask me.
Thanx in Advance,
-Revenge
P.S. I found this code at
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=267 It was an awsome article by Greg Chapman.