如何使用 Get-EventLog 在 PowerShell 中获得与 Get-WinEvent 相同的结果?

How do I use Get-EventLog to get the same result of Get-WinEvent in PowerShell?

我正在 Windows Server 2003 上工作,我需要通过使用此命令 Get-WinEvent -ListLog Application, Security, System

获得如下内容
LogMode   MaximumSizeInBytes RecordCount LogName
-------   ------------------ ----------- -------
Circular            33554432       15188 Application
Circular           201326592      298459 Security
Circular            33554432       10074 System

我需要 属性 MaximumSizeInBytes 的结果,但 Get-WinEvent 在 Server 2003 上不受支持

我看到 Get-EventLog 有一个名为 MaximumKilobytes 的 属性 但我得到的结果不同

我想知道是否有命令可以在本地运行得到相同的结果

首先你为什么还在玩WS2K3? --- ;-} 在你回应之前,我知道,我知道,一些组织......对吧!? ;-}

然而,除非此站点上的某人拥有 WS2K3,否则他们无法验证内容。

WS2K3 不支持此 cmdlet 不是错误或缺失。 cmdlet 是 OS 版本和 PowerShell 版本特定的。

话虽如此。仅仅因为您的系统上不存在命令,并不意味着您不能尝试使用它。

这就是存在隐式 PSRemoting 的原因。

Remoting the Implicit Way

Using implicit PowerShell remoting to import remote modules

大多数情况下,您会看到它用于 ADDS、Exchange、O365 cmdlet 等,但您可以对远程主机上的任何模块/cmdlet 执行此操作,以在本地会话中使用。使用隐式远程处理 cmdlet 实际上不会 运行 在您的系统上它被代理。请务必使用 -prefix 参数,以免最终列出重复的 cmdlet。

例子

$RemoteSession = New-PSSession -ComputerName 'RemoteHost' -Credential (Get-Credential -Credential "$env:USERDOMAIN$env:USERNAME")
Import-PSSession -Session $RemoteSession -Prefix RS

因此,当您想使用该会话中的 cmdlet 时,不可以使用前缀调用这些 cmdlet。

Get-RSWinEvent

现在,正如我所说,我已经没有 WS2K3 盒子可以乱搞了,因为我就是 WS2K12R2/16/19。然而,试一试。

由于还没有人提供令人满意的答案,我将 post 我在网上找到的答案 here。以下命令救了我一命:

Get-WmiObject -Class Win32_NTEventLogFile | Select-Object -Property MaxFileSize, LogfileName, Name, NumberOfRecords

我不会选择我自己的答案作为最终答案,所以如果你能想到更好的解决方案,请随时添加:)

感谢您查看我的 post 并尝试提供帮助