1

从下面的代码行中,有没有办法调用 .txt 文件来查看要查看的计算机列表?我希望它不仅在一台计算机上查找日志,而且从计算机列表中查找日志。

$StartDate = (get-date).AddHours(-12)
Get-WinEvent -FilterHashtable @{logname="System"; Level=1,2,3; starttime=$StartDate} -ErrorAction SilentlyContinue

希望早日收到你的消息!谢谢。

4

1 回答 1

1

由于 cmdlet 的-ComputerName参数Get-WinEvent只接受字符串,因此您可能必须遍历列表:

$StartDate = (get-date).AddHours(-12)

Get-Content 'computers.txt' | ForEach-Object {
    Get-WinEvent -ComputerName $_ -FilterHashtable @{logname="System"; Level=1,2,3; starttime=$StartDate} -ErrorAction SilentlyContinue    
}
于 2016-09-20T06:27:23.443 回答