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

Add to favorites
E-mail Twitter 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.
    • 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 }
      Function Global:Clear-Winevent ( $Logname ) {
      Given a specific Logname from the GET-WINEVENT Commandlet
      it will clear the Contents of that log
      Cmdlet used to clear the Windows Event logs from Windows 7
      Windows Vista, Server 2008 and Server 2008 R2
      CLEAR-WINEVENT -Logname Setup
      GET-WINEVENT -Listlog * | FOREACH { CLEAR-WINEVENT -Logname $_.Logname }
      Clear all Windows Event Logs
      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
      For those who are still confused on the topic ... check the was a great help to me.
    • anybody could use clear-event to clean Deployment-Services-Diagnostics's log?