Solved

How do modify this script to backup something other than the applications event log?

Posted on 2012-03-21
4
530 Views
Last Modified: 2012-08-14
I have the code below that backs up the applications event log, but instead of the applications event log I need it to back up a particular log file in the applications and services log (applications and service > softwarecompanyA).

How do I modify the code below to do it?

dtmThisDay = Day(Date)
dtmThisMonth = Month(Date)
dtmThisYear = Year(Date)
strBackupName = dtmThisYear & "_" & dtmThisMonth & "_" & dtmThisDay

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Backup)}!\\" & _
        strComputer & "\root\cimv2")

Set colLogFiles = objWMIService.ExecQuery _
    ("Select * from Win32_NTEventLogFile where LogFileName='Application'")

For Each objLogfile in colLogFiles
    objLogFile.BackupEventLog("c:\scripts\" & strBackupName & _
        "_application.evt")
Next
0
Comment
Question by:Kevin Smith
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
prashanthd earned 500 total points
ID: 37751184
Try following

Modify LogFile="Application" to the event log name you want to take backup example
LogFile="System"

dtmThisDay = Day(Date)
dtmThisMonth = Month(Date)
dtmThisYear = Year(Date)
strBackupName = dtmThisYear & "_" & dtmThisMonth & "_" & dtmThisDay
LogFile="Application"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Backup)}!\\" & _
        strComputer & "\root\cimv2")

Set colLogFiles = objWMIService.ExecQuery _
    ("Select * from Win32_NTEventLogFile where LogFileName='"& logfile &"'")

For Each objLogfile in colLogFiles
    objLogFile.BackupEventLog("c:\scripts\" & strBackupName & _
        "_"&logfile&".evt")
Next

Open in new window

0
 
LVL 12

Expert Comment

by:prashanthd
ID: 37751190
hmmm...Can you be more specific and give an example?
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37755255
Hi, I'm not that familiar with the new eventing, but have a look at the discussion here:
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_26696817.html

Basically, it looks like the wevtutil.exe command is your utility of choice, but you could also try Powershell.  VBScript doesn't seem capable of querying these new event logs.

Rob.
0
 

Author Closing Comment

by:Kevin Smith
ID: 37778741
perfect, thanks :)
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
This article explains how to install and use the NTBackup utility that comes with Windows Server.
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question