Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PowerShell中的Get EventLog远程查询多台服务器_Powershell - Fatal编程技术网

使用PowerShell中的Get EventLog远程查询多台服务器

使用PowerShell中的Get EventLog远程查询多台服务器,powershell,Powershell,我正在为我的晨练写一个PowerShell脚本。我只想从远程服务器列表中提取警告和错误。目前我只收到警告或错误。我不确定如何检索这两个。一旦我提取信息,它就不包括服务器。我的问题如下: # SERVER LIST PROPERTIES # Get computer list to check disk space. This is just a plain text file with the servers listed out. $computers = Get-Content "C:\M

我正在为我的晨练写一个PowerShell脚本。我只想从远程服务器列表中提取警告和错误。目前我只收到警告或错误。我不确定如何检索这两个。一旦我提取信息,它就不包括服务器。我的问题如下:

# SERVER LIST PROPERTIES
# Get computer list to check disk space. This is just a plain text file with the servers listed out.
 $computers = Get-Content "C:\MorningChecks.txt"; 

# QUERY COMPUTER SYSTEM EVENT LOG
foreach($computer in $computers)
{
 Get-EventLog -LogName System -EntryType Error -After (Get-Date).Adddays(-1) | Format-Table -Wrap ;
}

-EntryType
参数接受用于筛选的字符串数组

因此,要仅过滤错误,请使用以下参数:

Get-EventLog -LogName System -EntryType Error -After (Get-Date).Adddays(-1) 
要筛选错误和警告,请执行以下操作:

Get-EventLog -LogName System -EntryType "Error","Warning" -After (Get-Date).Adddays(-1) 
要获取计算机名,必须将其添加到
格式表
末尾的
-属性
参数中:

Format-Table -Wrap -Property MachineName, Index, TimeGenerated, EntryType, Source, InstanceID, Message -AutoSize
--编辑

要回答关于显示您自己机器的机器名称的问题,这是因为当您运行
Get EventLog
时,您只是在为本地机器运行它。您忘记在
foreach
循环中指定
-ComputerName
参数。您的foreach循环应该如下所示:

foreach($computer in $computers)
{
 Get-EventLog -ComputerName $computer -LogName System -EntryType "Error","Warning" -After (Get-Date).Adddays(-1) | Format-Table -Wrap -Property MachineName, Index, TimeGenerated, EntryType, Source, InstanceID, Message -AutoSize ;
}

非常感谢你。我仍然有一个问题。MachineName返回我的本地主机名。不是远程主机名。