Weekly quickTIP

Event! Create Thyself!

Keep a record of your scripting or batch file activity with this handy and simple event log tip.

No matter if your scripting mojo moves mountains or those hushed tones speak of your batch file prowess, sometimes you need to log system activity to a place where it'll be stored long term. One place to do that is within the event log.

Unlike storing data in a result file or pushing it to the screen, the event log stores status information for the long term. And, if your organization uses event log aggregator tools like Syslog or System Center Operations Manager to compile those logs into a central repository, you can essentially store that information forever.

Microsoft includes a tool in Windows XP and 2003 called "eventcreate" that enables the command-line creation of an event log entry. Although eventcreate by default creates log entries into the Application log, it can be configured to push event information to any log type.

To create an event in the default application log, use the syntax:

Eventcreate /s {ComputerName} /so {EventSource} /t {EventType} /id {EventID} /d {EventDescription}

For the above, the event source will be the source of the event from which you want the event to initiate. The event type will be the severity of the event, which can be "error," "warning," or "information." The event ID will be a number from 1 to 1,000 chosen by you for later searching and filtering. Lastly, the event description is the verbiage that you want to include in the event log entry.

Where this tool comes in handy is inside your batch files and scripts. If you've got batch files that perform work around your network, you can call this executable to leave a trace on each system the script touches.

Tech Help—Just An
E-Mail Away

Got a Windows, Exchange or virtualization question or need troubleshooting help? Or maybe you want a better explanation than provided in the manuals? Describe your dilemma in an e-mail to the MCPmag.com editors at [email protected]; the best questions get answered in this column and garner the questioner with a nifty Redmond T-shirt.

When you send your questions, please include your full first and last name, location, certifications (if any) with your message. (If you prefer to remain anonymous, specify this in your message, but submit the requested information for verification purposes.)

The same is true for your VBScript scripts. To call this executable from within a script, create a shell object and use its run method to invoke the script:

Set WshShell = WScript.CreateObject("WScript.Shell")
strCommand = "Eventcreate /so MyScript
   /l Application /t Error /ID 500 /D ""Script Success!"""
WshShell.Run strcommand

Using either method, this tool turns our typically read-only event logs into a read-write engine for efficient log storage.

About the Author

Greg Shields is Author Evangelist with PluralSight, and is a globally-recognized expert on systems management, virtualization, and cloud technologies. A multiple-year recipient of the Microsoft MVP, VMware vExpert, and Citrix CTP awards, Greg is a contributing editor for Redmond Magazine and Virtualization Review Magazine, and is a frequent speaker at IT conferences worldwide. Reach him on Twitter at @concentratedgreg.

comments powered by Disqus
Most   Popular

Upcoming Training Events