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
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
Thanks Laerte, this works great.
However, how do I write the computer name for each line so I can sort across multiple systems ? Thanks !
Pingback: Load Eventviewer files (evtx) to SQL Server Table with PowerShell | Jingyang Li (Limno)