【问题标题】:Powershell Script help : Windows events to Query and export to excelPowershell 脚本帮助:要查询和导出到 excel 的 Windows 事件
【发布时间】:2012-10-27 01:59:43
【问题描述】:

我有以下用于查询 Windows 事件的 powershell 脚本,尝试编写此脚本以获取计算机名称、事件 ID、源和描述信息到 excel。

$servers = get-content “c:\list.txt”
foreach ($server in $servers)
{
$server
Get-EventLog -LogName APPLICATION |Source "ACECLIENT" AND Where-Object { $_.EventID -eq 1001 } # I am not sure how to include here description "looking for 'File not found: C:\Program Files\Microsoft ISA Server\SDCONFIG.'" 
}

寻求帮助以完成此脚本。该脚本也可以在计算机列表上运行。

【问题讨论】:

    标签: powershell scripting vbscript


    【解决方案1】:
     $servers = get-content “c:\list.txt”
     $OututPath="C:\tst.csv"
    
     $start=[datetime]::Now.AddDays(-5)
     Get-EventLog -LogName Application -ComputerName $servers -Source "ACECLIENT" -Message "*File not found*" -After $start  | select MachineName, EventID, Message | Export-Csv $OututPath -NoTypeInformation
    

    希望我了解您要过滤的内容

    【讨论】:

    • 已经进行了一些更改以加快速度。我认为您需要确保源名称“ACECLIENT”正确并更改 where 语句以满足您的过滤器要求。我不确定您要查找的日志消息。
    • 我做了一些小改动,只获得了过去五天的事件,但脚本没有显示任何结果....任何人都可以在这里帮助我...请...
    • $servers = 获取内容“C:\list.txt” $OututPath="C\OUTPUT.csv" $fromtime = (get-date).Adddays(-5) 获取-eventlog -log 应用程序 -comp $servers |其中 {$_.source -eq "Defrag" -AND $_.EventID -eq 258 -and $_.message -like "磁盘碎片整理成功" -AND $_.TimeGenerated -EQ $从时间 } | Export-Csv $OututPath -NoTypeInformation
    • # 问题是我只想获取最近 5 天的事件,当我添加“-AND $_.TimeGenerated -EQ $FROMTIME”时,输出没有出现,它需要很多时间但不是结果。我认为一些逻辑问题..任何人都可以在这里帮助我...
    猜你喜欢
    • 2018-08-08
    • 2016-11-17
    • 2021-06-24
    • 1970-01-01
    • 1970-01-01
    • 2011-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多