CLEAR-WINEVENT

Global Function to add to Module or Profile - CLEAR Windows Event Logs

 
 
 
 
 
(0)
Add to favorites
3/9/2010
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Why wouldn't this work for 2003?
    4 Posts | Last post September 20, 2010
    • Just curious b/c I'm wanting to build something that uses this functionality but I need to support 2003 servers too if possible...  I'm very new to powershell but not scripting, so take that into consideration please.
      
      Cheers,
      Matt
    • Ahhh the answer to that is very easy.  Because the Event logs you are referring to within Server 2003 are known as the "Classic Event Logs" and are accessed with "GET-EVENTLOG" and "CLEAR-EVENTLOG".   This is designed for Server 2008, 2008R2, Windows7 and Windows Vista.
      
      Having said that, the Libary that calls UP the events may be universal, so you can easily testing using Powershell V2 on a Server 2003 box this command line
      
      GET-WINEVENT -ListLog *
      
      If you get your standard 5   eventlogs in there, you can use that Function :)
      
    • Hi,
      Please update the following so others don't get frustrated by the missing FOREACH.........
      
      Now this works very nice for clearing all the EVTX logfiles. :-)
      
      
      OLD entry in Module :
      GET-WINEVENT -Listlog * | CLEAR-WINEVENT -Logname $_.Logname
      
      NEW entry in Module :
      GET-WINEVENT -Listlog * | FOREACH { CLEAR-WINEVENT -Logname $_.Logname }
      
      
      MODULE
      =========================================================================================
      Function Global:Clear-Winevent ( $Logname ) {
      <#
      
      .SYNOPSIS 
      Given a specific Logname from the GET-WINEVENT Commandlet
      it will clear the Contents of that log
      
      .DESCRIPTION 
      Cmdlet used to clear the Windows Event logs from Windows 7
      Windows Vista, Server 2008 and Server 2008 R2
      
      .EXAMPLE 
      CLEAR-WINEVENT -Logname Setup
      
      .EXAMPLE 
      GET-WINEVENT -Listlog * | FOREACH { CLEAR-WINEVENT -Logname $_.Logname }
      
      Clear all Windows Event Logs
      
      .NOTES 
      This is a Cmdlet that is not presently in Powershell 2.0
      although there IS a GET-WINEVENT Command to list the
      Contents of the logs.  You can utilize this instead of
      WEVTUTIL.EXE to clear out Logs.  Special thanks to Shay Levy
      (@shaylevy on Twitter) for pointing out the needed code
      
      #>
      
      [System.Diagnostics.Eventing.Reader.EventLogSession]::GlobalSession.ClearLog("$Logname")
      
      }
      =========================================================================================
      
      For those who are still confused on the topic ... check the link...it was a great help to me.
      
      http://tfl09.blogspot.com/2009/01/modules-in-powershell-v2.html
      
      Cheers,
      
      Eduard
      
      
      
    • anybody could use clear-event to clean Deployment-Services-Diagnostics's log?