The help file of Clear-EventLog says that the -LogName parameter accept pipeline ByPropertyName. So, definitely, the following won’t work:
[pre]
Get-EventLog -LogName * | Clear-EventLog
[/pre]
However, why does the following not work either?
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.
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.
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.
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.