Please see the files that I'm using on my google drive:
Mod-edit: Link removed - it has audit access to the google drive.
Edit your security settings for the google drive folder so it is sharable but without audit access.
Code: Select all
:: 1_Run.bat
@echo.
@echo.
@echo ***************
@echo !!!ATTENTION!!!
@echo ***************
@echo.
@echo The purpose of this script is to CLEAR and ZIP logs on all systems identified in computers.txt
@echo.
set clearLog=n
set /p clearLog=Is this what you want to do? (y/[n]):
if %clearLog% == y goto Proceed
goto xit
:Proceed
set clrLog=n
@echo.
set /p clrLog=Do you want to clear the logs? (y/[n]):
set fileName= computers.txt
@echo.
set /p fileName=Enter computer list file name (default computers.txt):
@echo %fileName%
@echo.
@echo Proceeding...
@echo.
For /f "tokens=1 delims=, \" %%i in (%fileName%) do if not exist \\%%i\c$\Temp mkdir \\%%i\c$\Temp
For /f "tokens=1 delims=, \" %%i in (%fileName%) do cscript Application.vbs %%i
%clrLog%
For /f "tokens=1 delims=, \" %%i in (%fileName%) do cscript System.vbs %%i %clrLog%
For /f "tokens=1 delims=, \" %%i in (%fileName%) do cscript Security.vbs %%i
%clrLog%
@echo.
@echo Operation Completed.
@echo.
set copyLogs=n
@echo.
set /p copyLogs=Copy logs? (y/[n]):
if %copyLogs% == n goto noCopy
if not exist c:\Audits mkdir c:\Audits
FOR /f "tokens=1 delims=,\ " %%i in (%fileName%) do copy \\%%i\c$\Temp\*.evt
c:\Audits
:noCopy
set clrTemp=n
@echo.
set /p clrTemp=Clear temporary logs? (y/[n]):
if %clrTemp% == n goto noClear
Code: Select all
:: 2_copy.bat
if not exist c:\Audits mkdir c:\Audits
FOR /f "tokens=l delims=,\ " %%i in (computers.txt) do copy \\%%i\c$\Temp\*.evt
c:\Audits
Code: Select all
:: 3_Clean.bat
FOR /f "tokens=l delims=,\ "%%i in (servers.txt) do del \\%%i\c$\Temp\*.evt
pause
Code: Select all
' Application.vbs
strComputer = Wscript.Arguments.Item(0)
strClearLog = Wscript.Arguments.Item(1)
Wscript.Echo "Application::Computer: " & strComputer
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate, (Backup, Security)}!\\" & strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
("Select* from win32_NTEventLogFile where LogFileName='Application'")
For Each objLogfile in colLogFiles
FileName = strComputer & "-" & year(now) & "_"
FileName = FileName & month(now) & "-" & Day(Now)
FileName = FileName & "-app.evt"
OutputFile = "C:\Temp\" & FileName
errBackupLog = objLogFile.BackupEventLog(OutputFile)
If errBackupLog = 0 or errBackupLog = 183 Then
If strClearLog = "y" then
WScript.Echo "code:" & errBackupLog & ", clearing Log..."
objLogFile.clearEventLog()
Else
wscript.Echo "Code:" & errBackupLog & ", log not cleared..."
End If
Else
WScript.Echo strComputer & ": The Application event log could not be backed up."
wscript.Echo "Error Number: " & errBackupLog
End If
Next
Code: Select all
:: computers.txt
\\MyComputerName
Code: Select all
' Security.vbs
strComputer = WScript.Arguments.Item(O)
strClearLog = WScript.Arguments.Item(1)
WScript.Echo "Security::Computer: " & strComputer
set objWMIService = GetObject("winmgmts:"_
& "{impersonationLevel=impersonate, (Backup, Security)}!\\"_
& strComputer & "\root\cimv2")
set colLogFiles = objWMIService.ExecQuery _
("Select * from win32_NTEventLogFile where LogFileName='Security'")
For Each objLogfile in colLogFiles
FileName = strComputer & "-" & year(now) & "_"
FileName = FileName & month(now) & "-" & Day(Now)
FileName = FileName & "-sec.evt"
OutputFile = "C:\Temp\" & FileName
errBackupLog = objLogFile.BackupEventLog(OutputFile)
If errBackupLog = 0 Or errBackupLog = 183 Then
If strClearLog = "y" then
WScript.Echo "Code:" & errBackupLog & ", clearing Log..."
objLogFile.ClearEventLog()
Else
WScript.Echo "Code:" & errBackupLog & ", log not cleared..."
End If
Else
WScript.Echo strComputer & ": The Application event log could not be backed up."
WScript.Echo "Error Number: " & errBackupLog
End If
Next
Code: Select all
' System.vbs
strComputer = WScript.Arguments.Item(O)
strClearLog = WScript.Arguments.Item(1)
WScript.Echo "System::Computer: " & strComputer
Set objWMIService = GetObject("winmgmts:"_
& "{impersonationLevel=impersonate, (Backup, Security)}!\\"_
& strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
("Select * from Win32_NTEventLogFile where LogFileName='System'")
For Each objLogfile in colLogFiles
FileName strComputer & "-" &year(now) & "_"
FileName = FileName & month(now) & "-" & Day(Now)
FileName = FileName & "-sys.evt"
outputFile = "C:\Temp\" & FileName
errBackupLog = objLogFile.BackupEventLog(OutputFile)
If errBackupLog = 0 Or errBackupLog = 183 Then
If strClearLog = "y" then
WScript.Echo "Code:" & errBackupLog & ", clearing Log..."
objLogFile.clearEventLog()Else
WScript.Echo "Code:" & errBackupLog & ", log not cleared..."
End If
Else
WScript.Echo strComputer & ": The Application event log could not be backed up."
WScript.Echo "Error Number: " & errBackupLog
End If
Next
Any help would be greatly appreciated.