Solved

Windows Event Logs

Posted on 2013-11-16
4
396 Views
Last Modified: 2013-11-17
Hi everyone,

I am trying to return events in the Application log from 00:01 to 02:00 on the same day I run the script below :

Get-WinEvent -ComputerName homePC -FilterHashtable @{LogName='application'; starttime=([datetime]::today.AddDays(-1)); endtime=([datetime]::Today); id=1007} | format-list * | select MachineName, ID, TimeCreated, Message

The problem I have is I can only get the last 24 hours rather than running the script on the same days and only list the event id:1007 in the past 24 hours rather than just between 00:00 and 02:00.

Can anyone help, please.
0
Comment
Question by:CaussyR
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
Comment Utility
If I'm understanding your date restrictions right, the below will work.
Get-WinEvent -ComputerName homePC -FilterHashtable @{LogName='Application'; starttime=([datetime]::Today); endtime=([datetime]::Today.AddHours(2)); id=1007} | select MachineName, ID, TimeCreated, Message | fl *

Open in new window

By the way, you can't have the Select-Object command after Format-List and expect to get anything, as the objects output from the Format commands don't include the properties of the objects input to them.  The Format commands should always be the last in the pipeline.
0
 

Author Comment

by:CaussyR
Comment Utility
Thanks, that's exactly what I was looking for. I couldn't find anything on addhours, how did you find out the additional attributes ?
0
 
LVL 39

Expert Comment

by:footech
Comment Utility
Not sure if I read about it first, or just saw it as an available method for datetime objects (it's been a while).  You can use Get-Member to see the properties and methods for an object.  Here's a couple examples.
[datetime]::now | gm
get-date | gm

In the first example, a static property is also used.  A static method or property is referenced by the type, then a double colon, followed by the property or method.  You can see what static methods and properties are available with something like the following.
get-date | gm -static
0
 

Author Comment

by:CaussyR
Comment Utility
Thank you for all your help FooTech.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will help you understand what HashTables are and how to use them in PowerShell.
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now