Powershell 使用Win32\u NTLogEvent的CimSession

Powershell 使用Win32\u NTLogEvent的CimSession,powershell,powershell-3.0,event-log,Powershell,Powershell 3.0,Event Log,我目前正在学习powershell,并尝试仅使用凭据从多个服务器获取系统和应用程序事件日志错误和警告。对于本脚本中的其他内容,我已经能够将CimSession与Get-CimInstance一起使用,但它似乎不适用于Win32\u NTLogEvent。我也尝试过查看Get WinEvent,但不确定如何将其过滤为只包含错误和警告。这基本上取代了过去的Get Eventlog,只是现在需要凭据 以前的代码: Get-Eventlog -LogName System -ComputerName $

我目前正在学习powershell,并尝试仅使用凭据从多个服务器获取系统和应用程序事件日志错误和警告。对于本脚本中的其他内容,我已经能够将CimSession与Get-CimInstance一起使用,但它似乎不适用于Win32\u NTLogEvent。我也尝试过查看Get WinEvent,但不确定如何将其过滤为只包含错误和警告。这基本上取代了过去的Get Eventlog,只是现在需要凭据

以前的代码:

Get-Eventlog -LogName System -ComputerName $server -EntryType error,warning -Newest 20
Get-Eventlog -Logname Application -ComputerName $server -EntryType error,warning -Newest 20
目前的尝试:

如前所述,我不知道如何使用Get WinEvent过滤Get Eventlog中的条目类型

Get-WinEvent -LogName System -ComputerName $server -Credential $cred
对于Get-CimInstance,我不能使用CimSession

Get-CimInstance -ClassName Win32_NTLogEvent`
-filter 'type="error" or type="warning" and (logfile="system" or logfile="application")'`
|Select-Object -first 20

这是因为Win32\u NTLogEvent来自WMIObject还是有其他原因?还有什么我可以用的吗?或者我应该用管道将WinEvent连接到什么地方?

当我将其用于远程服务器时,它无法单独工作。不过,我发现在powershell会话中使用Get Eventlog工作得非常好

$PSS= New-PSSession -computername $server -credential $cred
Invoke-command -session $PSS -scriptblock {Get-Eventlog -Logname Application -EntryType error,warning -Newest 20} 

也谢谢你,无论是谁,把问题从否定的位置投了赞成票,我真的很感激。我保证我不是在寻找分数或任何东西,我只是觉得在没有给出理由的情况下否决一个问题是不礼貌的。

我通过使用powershell会话运行get eventlog找到了解决方案。虽然如果有人有任何答案,我仍然对能做些什么感兴趣。顺便说一句,我是新来的,如果你要投反对票,我会很感激,你至少可以体面地解释一下原因。你给了这个网站一个全新的人一个相当负面的看法。你的第一个例子对我来说很有用Get Eventlog-Logname Application-computer localhost-EntryType error-我在远程服务器上使用它,它不会单独工作。不过,通过PSSession使用它确实可以$PSS=New PSSession-computername$server-credential$cred新行Invoke命令-session$PSS-scriptblock{Get Eventlog-Logname Application-EntryType error,warning-newst 20}也感谢所有投票反对的人,我非常感谢。