标题: [转载代码] [PowerShell每日技巧]查看一天内的错误事件日志(20140312) [打印本页]
作者: DAIC 时间: 2014-3-13 16:50 标题: [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):- $today = Get-Date
- $1day = New-TimeSpan -Days 1
- $yesterday = $today - $1day
- Get-EventLog -LogName system -EntryType Error, Warning -After $yesterday
复制代码
http://powershell.com/cs/blogs/tips/archive/2014/03/12/finding-errors-since-yesterday.aspx
作者: DAIC 时间: 2014-3-13 16:51
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.- 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.- Get-EventLog -LogName system -EntryType Error, Warning -After (Get-Date).Date.AddDays(-1)
复制代码
作者: DAIC 时间: 2014-3-13 16:52
I want to get all error and warning events from the System log since yesterday start of day.- $yesterday1200AM = ( [datetime](Get-Date).ToShortDateString()).adddays(-1)
- $yesterday1200AM
- Get-EventLog -LogName system -EntryType Error, Warning -After $yesterday1200AM
复制代码
作者: 522235677 时间: 2014-3-13 17:03
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
作者: DAIC 时间: 2014-3-13 19:23
回复 4# 522235677 - Set-ExecutionPolicy Unrestricted
复制代码
http://www.bathome.net/thread-26149-1-1.html
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |