找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 16846|回复: 4

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

[复制链接]
发表于 2014-3-13 16:50:49 | 显示全部楼层 |阅读模式
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
 楼主| 发表于 2014-3-13 16:51:22 | 显示全部楼层
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)
复制代码
 楼主| 发表于 2014-3-13 16:52:21 | 显示全部楼层
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
复制代码
发表于 2014-3-13 17:03:43 | 显示全部楼层
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
 楼主| 发表于 2014-3-13 19:23:45 | 显示全部楼层
回复 4# 522235677
  1. Set-ExecutionPolicy Unrestricted
复制代码
http://www.bathome.net/thread-26149-1-1.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-16 23:52 , Processed in 0.021771 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表