[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[转载代码] [PowerShell每日技巧]查看一天内的错误事件日志(20140312)

Relative dates are important to get data within a special time frame, avoiding hard-coded dates and times.

This script will get all error and warning events from the System log since yesterday (24 hours ago):
  1. $today = Get-Date
  2. $1day = New-TimeSpan -Days 1
  3. $yesterday = $today - $1day
  4. Get-EventLog -LogName system -EntryType Error, Warning -After $yesterday
复制代码
http://powershell.com/cs/blogs/tips/archive/2014/03/12/finding-errors-since-yesterday.aspx

For those looking for a one-liner alternative, you can use the AddDays method as shown in the following command to retrieve events for the last 24 hours.
  1. Get-EventLog -LogName system -EntryType Error, Warning -After (Get-Date).AddDays(-1)
复制代码
To retrieve events from yesterday starting at midnight, use the Date method prior to AddDays.
  1. Get-EventLog -LogName system -EntryType Error, Warning -After (Get-Date).Date.AddDays(-1)
复制代码

TOP

I want to get all error and warning events from the System log since yesterday start of day.
  1. $yesterday1200AM = ( [datetime](Get-Date).ToShortDateString()).adddays(-1)
  2. $yesterday1200AM
  3. Get-EventLog -LogName system -EntryType Error, Warning -After $yesterday1200AM
复制代码

TOP

C:\Users\Admin>powershell -file "C:\Users\Admin\Desktop\test.ps1"
无法加载文件 C:\Users\Admin\Desktop\test.ps1,因为在此系统中禁止执行脚本。有关
详细信息,请参阅 "get-help about_signing"。
    + CategoryInfo          : NotSpecified: ( [], ParentContainsErrorRecordE
   xception
    + FullyQualifiedErrorId : RuntimeException

TOP

回复 4# 522235677
  1. Set-ExecutionPolicy Unrestricted
复制代码
http://www.bathome.net/thread-26149-1-1.html

TOP

返回列表