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

问题描述 投票:0回答:2

我正在使用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的结果,但Server 2003不支持Get-WinEvent

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

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

powershell windows-server-2003
2个回答
1
投票

首先为什么你还在使用WS2K3? ---; - }在你回答之前,我知道,我知道,有些组织......对吧!? ; - }

然而,除非这个网站上有人拥有WS2K3,否则他们无法验证内容。

WS2K3上不支持此cmdlet不是错误或丢失的东西。 cmdlet是操作系统版本和特定于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。

Get-RSWinEvent

现在,正如我所说,我没有WS2K3盒子,因为我都是WS2K12R2 / 16/19。但是,试一试。


0
投票

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

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.