Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to change this line ("Select * from Win32_NTEventLogFile") Example</p> <p>("Select * from Win32_NTEventLogFile where LogFileName='Application'")</p> <p>Add in filter for the logs you wish to backup see <a href="http://social.technet.microsoft.com/Forums/scriptcenter/en-US/febbb896-e7fb-42c6-9b1b-6f3e3b293b22/event-viewer-log-script-only-working-for-application-event-log" rel="nofollow">http://social.technet.microsoft.com/Forums/scriptcenter/en-US/febbb896-e7fb-42c6-9b1b-6f3e3b293b22/event-viewer-log-script-only-working-for-application-event-log</a></p> <p>OR</p> <p><a href="http://www.activexperts.com/activmonitor/windowsmanagement/scripts/logs/event/" rel="nofollow">http://www.activexperts.com/activmonitor/windowsmanagement/scripts/logs/event/</a></p> <p>This should help you.</p> <p>See the following altered code for your requirements, will output required logs and save to a different folder each day.</p> <p>VBS</p> <pre><code>Dim strComputer, objDir2 Dim current: current = Now Dim strDateStamp: strDateStamp = dateStamp(current) strComputer = "YourServer" objDir2 = "Your File Server Path" &amp; strDateStamp Dim objDir1: objDir1 = "\\" &amp; strComputer &amp; "\c$\EVT" clearEVTLogs = "No" Set filesys=CreateObject("Scripting.FileSystemObject") If Not filesys.FolderExists(objDir1) Then createDir(objDir1) If Not filesys.FolderExists(objDir2) Then createDir(objDir2) End If strPath = objDir2 &amp; "\" Set objWMIService = GetObject("winmgmts:" _ &amp; "{impersonationLevel=impersonate, (Backup, Security)}!\\" _ &amp; strComputer &amp; "\root\cimv2") Set colLogFiles = objWMIService.ExecQuery _ ("Select * from Win32_NTEventLogFile where LogFileName='Application' Or LogFileName='Security' Or LogFileName='System'") For Each objLogfile In colLogFiles strCopyFile = strDateStamp &amp; "_" &amp; strComputer &amp; "_" _ &amp; objLogFile.LogFileName &amp; ".evt" strBackupFile = "c:\EVT\" &amp; strDateStamp &amp; "_" _ &amp; strComputer &amp; "_" &amp; objLogFile.LogFileName &amp; ".evt" strBackupLog = objLogFile.BackupEventLog _ (strBackupFile) Call copyAFile(objDir1, strPath, strCopyFile) If clearEVTLogs = "Yes" Then objLogFile.ClearEventLog() End If Next Function dateStamp(ByVal dt) Dim y, m, d y = Year(dt) m = Month(dt) If Len(m) = 1 Then m = "0" &amp; m d = Day(dt) If Len(d) = 1 Then d = "0" &amp; d dateStamp = y &amp; m &amp; d End Function Function copyAFile( Byval strSourceFolder, Byval strTargetFolder, _ Byval strFileName) Dim objFSO, booOverWrite, strResult Set objFSO = CreateObject( "Scripting.FileSystemObject") If objFSO.FileExists( strSourceFolder &amp; "\" &amp; strFileName) _ And UCase( strSourceFolder) &lt;&gt; UCase( strTargetFolder) Then If objFSO.FolderExists( strTargetFolder) Then Else strResult = "The destination folder does not exist!" 'copyAFile = strResult Exit Function End If If objFSO.FileExists( strTargetFolder &amp; "\" &amp; strFileName) Then strResult = "The file exists, overwritten" booOverWrite = vbTrue Else strResult = "The file does not exist, created" booOverWrite = vbFalse End If objFSO.CopyFile strSourceFolder &amp; "\" _ &amp; strFileName, strTargetFolder &amp; "\", booOverWrite Else strResult = "The source file does not exist, or " _ &amp; "identical Source and Target folders!" End If End Function Function createDir(strDir) Set filesys=CreateObject("Scripting.FileSystemObject") Set objFSO = CreateObject("Scripting.FileSystemObject") wscript.echo strDir If Not filesys.FolderExists(strDir) Then Set objFolder = objFSO.CreateFolder(strDir) End If End Function </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload