• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 491
  • Last Modified:

Display Event Logs For A Particular Time

Hi Everyone,

I am trying to retrieve the System event logs from 05:50 to 06:00.  See script below :

$Date = Get-date -DisplayHint Date
$Server = get-content C:\temp\servers.txt
$AppLog = Get-EventLog -LogName System -computername $Server -After ("$Date 05:50:00") -Before ("$Date 06:00:00")

$AppLog | Format-Table -AutoSize MAchineNAme, TimeGenerated, Source, Message

I have retrieved the Date and placed it into the $Date variable. Using the $Date I add the time, 05:50:00 and 06:00:00 as the Before and After times.

When I run the above I get the following error :

Get-EventLog : Cannot bind parameter 'After'. Cannot convert value "10/17/2013 06:35:49 05:50:00" to type "System.DateTime". Error: "String was not
recognized as a valid DateTime."
At line:3 char:69
+ $AppLog = Get-EventLog -LogName System -computername $Server -After ("$Date 05:5 ...
+                                                                     ~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-EventLog], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetEventLogCommand
1 Solution
Rainer JeschorCommented:
please exchange your first line and try this instead
$Date = Get-date -format d

CaussyRAuthor Commented:
Thank you very much that worked.....
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now