Question about Clear-EventLog and pipeline

Hi Experts,

The help file of Clear-EventLog says that the -LogName parameter accept pipeline ByPropertyName. So, definitely, the following won’t work:
Get-EventLog -LogName * | Clear-EventLog
However, why does the following not work either?

Get-EventLog -LogName * |
Select-Object @{n=‘LogName’; e={$_.Log}} |

Thanks in advance!!


welcome to Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!

Then … when you post code, error messages, sample data or console output format it as code, please.
Here you can read how that works: Guide to Posting Code.
You can go back and edit your existing post. You don’t have to create a new one. :wink:


You may have to continue reading the help until the “Inputs” paragraph. :wink:

You cannot pipe objects to Clear-EventLog.

So you would need to convert the output you get from Get-EventLog to a string array and pipe that to Clear-EventLog. The help even shows that in example #4.

So this actually works on my test pc:

function clear-all-event-logs {
   $logs = Get-EventLog  -List | ForEach-Object {$_.Log}
   $logs | ForEach-Object {Clear-EventLog -LogName $_}
   Get-EventLog -list



Hi Olaf,

Thank you very much for your prompt reply!!

Yes, I know the usage described in Example 4 of the help, but I really don’t know what “You cannot pipe object to Clear-EventLog.” mean in the Inputs paragraph.

The help file says -LogName parameter accept pipeline ByPropertyName. Why cannot I pipeline objects with a property named LogName to it? Can you please explain this to me? To me, the usage of Clear-EventLog in Example 4 is not pipeline (because it appears in the foreach block). I really want to know how Clear-EventLog can be used in a real pipeline. Thanks again.

Can anyone else answer my question? Thanks.

I believe the documentation is wrong in the parameters section. If it can’t accept objects over the pipeline then all parameters should have False on the “Accept pipeline input?” question.