【发布时间】:2017-04-17 18:34:18
【问题描述】:
我是一名 SQL DBA,不熟悉 Powershell,目前负责系统管理员职责
我需要在我的服务器上查询错误日志以获取错误和警告。
使用我自己的 Google-fu 和 this 线程的帮助,我能够得到这个工作:
$computers = Get-Content "C:\Servers\ServerList_Short.txt";
# QUERY COMPUTER SYSTEM EVENT LOG
foreach($computer in $computers)
{
Get-EventLog -ComputerName $computer -LogName System -EntryType "Error","Warning" -After (Get-Date).Adddays(-7) `
| Select-Object -Property machineName, EntryType, EventID, TimeGenerated, Message `
| Format-Table -Property MachineName, TimeGenerated, EntryType, Source, Message -AutoSize ;
}
我目前缺少的是如何在我的 .txt 文件中捕获离线的服务器,忽略它并移至下一个。之后,我将努力将所有这些转储到 SQL 表、results.txt 等中。
感谢您的帮助:)]
凯文3NF
【问题讨论】:
标签: windows powershell get-eventlog