Quick Tip–Storing Get-EventLog output into a SQL Server table


Yesterday my good friend Marcos Freccia (blog | twitter) asked me a simple and fast way to save the output of get-eventlog on a SQL Server table. Well the easiest and fastest way that  I know is using the functions of the Chad Miller (Out-DataTable and Write-DataTable), because the write-datatable using bulk insert. I took the liberty to change the write-datatable to get the object by Pipeline, and you can download below.

But the solution is :

Firts Create the table :

   1: CREATE TABLE [dbo].[EventError](

   2:     [SuccessAudit] [varchar](max) NULL,

   3:     [InstanceID] [varchar](max) NULL,

   4:     [Message] [varchar](max) NULL,

   5:     [TimeGenerated] [datetime] NULL

   6: ) ON [PRIMARY]

then the Posh script :

   1: Get-EventLog -ComputerName Computer -LogName Security -After "22-08-2011"  | select SuccessAudit,InstanceID,Message | Out-DataTable | Write-DataTable -ServerInstance Server -Database Database -TableName EventError 

Simple, Fast and Clean. As always when we are using PowerShell.

Donwload Out-DataTable/Write-DataTable

#PowerShellLifeStyle

About Laerte Junior

Laerte Junior Laerte Junior is a SQL Server specialist and an active member of WW SQL Server and the Windows PowerShell community. He also is a huge Star Wars fan (yes, he has the Darth Vader´s Helmet with the voice changer). He has a passion for DC comics and living the simple life. "May The Force be with all of us"
This entry was posted in Powershell, SQL SERVER EM GERAL, Virtual Pass BR. Bookmark the permalink.

3 Responses to Quick Tip–Storing Get-EventLog output into a SQL Server table

  1. Many thanks to you my friend.. I am using this script in a very important project for a costumer in Brazil… you really rocks with your #poweshellLifeStyle 🙂

    Regards,
    Marcos Freccia

  2. Loon says:

    Thanks Laerte, this works great.
    However, how do I write the computer name for each line so I can sort across multiple systems ? Thanks !

  3. Pingback: Load Eventviewer files (evtx) to SQL Server Table with PowerShell | Jingyang Li (Limno)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s