我是 SQL DBA,n00b 到 Powershell,目前负责系统管理员职责
我需要在我的服务器上查询错误日志以获取错误和警告。
使用我自己的 Google-fu 和这个线程的帮助,我能够得到这个工作:
$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