I'm assuming that this is a follow-up to your previous post, Using WMI to get printer logs
As I noted in my answer to that question, you ought to be filtering at the source - Get-EventLog
- instead of in a Where-Object
. Get-EventLog
provides two parameters for this - -Before
and -After
.
By filtering at the source, you will send a lot less data over the wire, which can be a significant performance improvement. It'll also reduce the time required by the remote system to process your request. Why ask for and retrieve data which you will discard without even looking at?
To get everything between one week ago and right now, do the following:
get-eventlog -computername ******* -logname system -after $((get-date).adddays(-7).date) -before $(get-date) -source Print | select-object eventid,timegenerated,message |export-CSV -Path "C:\temp\export.csv"
Change the values passed to -After
and -Before
as needed.