Using PowerShell To Search The Event Log

The “30-minute DBA” was operating in a highly effective mode. He’d automated most everything that could be automated. The first half hour of each day was spent reviewing the automated reports that landed in his inbox over night, taking actions as necessary. That’s why he’s paid the big bucks and gets to spend the balance of his time playing and learning.

“I’m convinced that he actually works 30 minutes a day and the rest of his time is spent playing around with cool SQL Server things in his test lab.” That’s what another DBA told me about the 30-Minute DBA.

Searching The Event Logs

There are a lot of options for automation. PowerShell has become one of my favorites. For example, PowerShell can be used to peek into the Windows Event Log, searching for anything of interest to you. I’ve already written about one way to sift through the events; now I’ll share a few more options.

To examine the Application Event Log, invoke the following cmdlet in PowerShell

Get-EventLog Application;

You can narrow the results to only those entries that are of type Error using the EntryType parameter.

Get-EventLog Application -EntryType Error;

You can further limit the results by looking at only the past 24 hours.

Get-EventLog Application -EntryType Error -After (Get-Date).AddDays(-1);

Using the Message parameter, you can search for specific words or phrases in the error message.

Get-EventLog Application -Message "*failed*";

If a specific event becomes a sporadic problem, you can search for the event using the Where functionality.

Get-EventLog Application | where {$_.EventId -eq 1309} | Format-Table -autosize;

Using these techniques, you can easily set up your own automated Event Log review process and insert the results into an email, a spreadsheet , or a database table for review.

Question:

  • What techniques are you using to automate your daily tasks?
  • What do you wish you could automate?

Hello, I’m a Mac

Years ago, I decided to move my SQL Server and Visual Studio work into Virtual Machines. The impetus was to make it easier for me to quickly create and maintain specific environment for specific projects and clients.

You see before I went virtual, I would load the latest and greatest version of a tool or application on my laptop. Sometimes I would keep a couple of revisions back, too. And as storage space became an issue, I would uninstall the oldest version to make room. However this technique effectively made it very difficult for me to support clients that still used older versions.

Enter Virtual Machines

So, I decided to move my entire development, administration, and presentation environment to virtual machines. This would allow me to have self-contained and dedicated environments that I could copy off to cheap external storage as drive space dictated.

I started with VirtualPC, but that proved to be lacking in many ways so I quickly moved to VMWare Workstation. It was good. I liked it. It met my needs.

With all of my SQL and development stuff in virtual machines, I soon realized that the only activities that I used my host operating system for was email, browsing the web, and blogging. And I could do that in most any operating system I wanted. I was no longer tied to Windows as my only choice.

I had had some previous experience with Linux and found it to be pretty user friendly, as stable as Windows, and faster than Windows on a given set of hardware. So I made the switch. Linux became my operating system of choice. That was four years ago; I’ve since blogged about the virtualization setup here.

Think Different

Using Linux has been a good experience. It’s fast, free, and I haven’t had to worry about viruses, trojans, and the like. Those who have the knowledge to write those kinds of destructive programs typically use their skills to make Linux better not tear it down.

But Linux is no nirvana; there have been some bumps along the way. Sometimes a kernel upgrade will cause the sound to stop working or the window manager to freak out and not display anything. The Linux community is great and usually these issues take only a couple of hours to resolve.

Apart from upgrades there are some other relatively minor inconveniences when using Linux. One is that many applications won’t run on Linux. iTunes is a good example of this; there are Mac and Windows versions of the application but Linux users are left out in the cold. (Some have successfully gotten some Windows versions of applications to run in Linux using Wine but that’s a non-trivial ordeal.) Fortunately, there are frequently very good Linux equivalents to these applications. Another annoyance is that there maybe some incompatibility with other software applications. For example OpenOffice does a very poor job with Office 2007 file formats.

These annoyances have relatively minor over the years. And I believe better than running the traditional Windows operating system. However this time when it came time to replace my laptop, I decided to “Think Different”. I bought a MacBook Pro.

I’ve had it a week now and even though I’m a complete newbie, it’s been a very pleasant experience. The learning curve hasn’t been steep. The hardware is solid, the software is intuitive, and the graphics are great.

I’m still getting use to some of the ways that Macs do things. For example, clicking on the X doesn’t actually close the application, only the window. I’m an avid user of keyboard shortcuts and there are some different mappings on the Mac. I’m still getting use to those. My MacBook Pro doesn’t have the Home, End, PageUp and PageDown keys and that is taking quite a bit of getting use to.

I’ll blog more about my virtualization setup in another post. (Thanks to Aaron Bertrand (blog, twitter) for sharing his setup here.)

For now, I’m well on my way to joining the ranks of Brent Ozar (blog, twitter) and Aaron in the SQL/Apple Fanboy club.

My Virtualization Setup

A couple of months ago, I blogged about the benefits of desktop virtualization. Since then, I’ve received several questions about my configuration and why I chose it. So, I thought I’d share with you the choices I’ve made and why I made them.

The Hardware
Let’s start with the hardware. As a consultant, I need to be mobile. I regularly work at different locations. Whether working from home, visiting a client, or traveling 500 miles per hour in a plane at 30,000 feet. I need to have my work-related stuff at my fingertips.

So, a desktop replacement laptop is my computer of choice. Mine is not necessarily the lightest laptop around and I must admit that when someone near me is sporting a 3 pound mini laptop I occasionally look on with a bit of envy. But, I take comfort in knowing that I have more computational power in my laptop than exists on the Space Shuttle. Plus I get a little exercise when carrying it.

For 10+ years, I’ve used Toshiba laptops. They’ve been rock solid and I’ve never had a hardware related problem with one. The only downside, and it’s significant if you travel, is that they have a horrible battery life. I’ve had a case of the hiccups that lasted longer than my Toshiba laptop battery.

For my current laptop, however, I choose a Dell Inspiron because I could custom configure it rather than having to take a prepackaged configuration from Toshiba. So far, it’s been good. Knock, knock, knock.

It’s nothing fancy. It’s a Dual Core Centrino laptop running at 2.0 GHz. It has 4GB of RAM and a 7200 RPM 160 GB hard disk drive. Certainly not top of the line, but it meets my needs.

My Operating System
For reasons I mentioned in the prior blog posting, I moved into a virtualized environment several years ago while using Windows XP as my operating system of choice.

Once I made that move, I quickly realized that the only activities that remained in my host operating system were email, blogging, writing, and other office related endeavors. All of these could easily be done in most any operating system. So I made the switch to Ubuntu Linux.

Using the LiveCD, the switch as very easy. With a LiveCD, you can boot your computer from the CD or DVD and run the operating system from there without installing anything on your computer, testing it to make sure Ubuntu will work properly with your hardware. If you like it, you can click a button the the desktop to install the operating system on your hard drive. It recognizes your configuration and asks what you’d like to do. For instance, it recognized that I had Windows installed and asked if I wanted to keep that installation and dual boot or replace it. When I chose dual boot, it asked about resizing my partitions to make room for Ubuntu. (It didn’t even mock me for wanting to dual boot.) Overall it was a very nice installation.

I started with dual booting my laptop for a while but over time realized that I didn’t need the Windows partition anymore so I got rid of it. Now I only have Ubuntu on my laptop.

My Virtualization Software
Although there are some open source applications available, I pay to license VMWare’s Workstation for my virtualization. It’s very nice. It allows you to manage your virtual machines and their settings pretty easily. You can clone VMs, take snapshots of them, etc.

I have several VMs that I use for different purposes, include some for development and administration, some for demonstration purposes, some for billing and invoicing, and even one for my iTunes account. Anything that I want to keep isolated for whatever reason, gets its own VM.

Other software applications
But I don’t do everything in Virtual Machines. I use quite a bit of open source software that is very good.

  • Office software – I use OpenOffice for my word processing and spreadsheet needs. It’s completely interchangeable with their Microsoft counterparts. For example, when I write magazine articles, I do it in OpenOffice and save them in Microsoft Word format. When I submit them to my editors, they never know the difference. We even send the articles back and forth using the Track Changes feature. It works great for 2003 and earlier formats, but only Ok for 2007 formats. I expect that’ll get better over time.
  • Email, calendering, etc – There are number of applications for Linux that are similar to Microsoft Outlook. Evolution, Thunderbird, and others can do most everything that I need, but I’ve opted for a completely online experience using web-based mail, calendaring, and task and contact management. I use Google for the first two, Remember The Milk for task management, and Plaxo for contact management. Having all of that available to me online, regardless of the computer happen to be using is nice. Plus it makes sync’ing with my iPhone unnecessary. It’s all available to me automatically.
  • Remote Desktop – Ubuntu comes with a good Remote Desktop software that allows me to RDP into Windows computers and servers.
  • Twittering - Adobe Air is available for Linux and I use it to run TweetDeck.
  • Text Editing – Emacs is my text editor or choice on either Windows or Linux.
  • SQL Client - RazorSQL is a java-based SQL client that works with SQL Server and other RDBMS’.
  • Graphics – Gimp, just as powerful a Photoshop, yet free.
  • Newsreader – Pan. It’s somewhat similar to Forte Agent, but doesn’t seem to be as powerful or flexible.
  • Instant Messaging – Pidgin works with all of the major IM protocols including MSN, Yahoo, etc.
  • Music – RhythmBox Music Player. Similar to iTunes.
  • Blogging – I’m currently testing ScribeFire, an add-on for Firefox for my blogging client.

Other things that I really like
I use Compiz as my windows manager in Linux. It has great graphics capabilities, including allowing me to view my four workspaces as a cube. If you’re not familiar with the workspaces concept, think of it as 4 different monitors or desktops in the Windows environment. Each is separate. You can open windows or applications in each of the workspaces without cluttering up any one desktop. I typically have email opened in one workspace, a virtual machine in another, TweetDeck in a third, and perhaps a browsers in the fourth.

Some things that I miss
Although there are Open Source equivalents in Linux for most things windows, there are some applications that are just far better in Windows. Some that come to mind are:

  • PowerPoint 2007 – It’s simply far better than it’s OpenOffice equivalent.
  • LiveWriter – Is probably one of the best blogging clients around.

Using Wine, you can theoretically run programs designed for Windows in Linux. I haven’t tried this myself, but I hear it has mixed results depending on the application itself.

Well there you have it. My virtualized work environment.

Are you virtualized? I’d love to hear about it. And if not, why not?

Cheers!

Joe

Follow

Get every new post delivered to your Inbox.

Join 32 other followers