Get-EventLog -Log“Microsoft-Windows-Ntfs/Operational”失败,并显示“不存在”

Get-EventLog -Log“Microsoft-Windows-Ntfs/Operational”失败,并显示“不存在”

我正在编写一个脚本,用于提取所有非空日志并将它们保存为 evtx、csv 或 xml。我已经让脚本适用于基本日志(应用程序、安全、系统等)以及那些带有空格的日志。但是,我不断收到带有正斜杠(/)的错误(例如Microsoft-Windows-Ntfs/Operational)。我尝试用破折号、空格、缩写和下划线替换它们/:它们都会导致以下错误。

笔记:我正在使用-newest 20代码进行测试,以减轻负载并节省时间。

代码示例(使用任一方法均可获得相同的结果):

get-eventlog -log "Microsoft-Windows-Ntfs/Operational" -newest 20

或者

$Logname = "Microsoft-Windows-Ntfs/Operational"
get-eventlog -log $logname -newest 20`

错误:

get-eventlog : The event log 'Microsoft-Windows-Ntfs/Operational' on computer '.' does not exist.
At line:1 char:1
+ get-eventlog -log "Microsoft-Windows-Ntfs/Operational" -newest 20
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-EventLog], InvalidOperationException
    + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.GetEventLogCommand

答案1

获取事件日志只看到这个

> get-eventlog -List

  Max(K) Retain OverflowAction        Entries Log
  ------ ------ --------------        ------- ---
  20’480      0 OverwriteAsNeeded      18’888 Application
  20’480      0 OverwriteAsNeeded           0 HardwareEvents
     512      7 OverwriteOlder              0 Internet Explorer
  20’480      0 OverwriteAsNeeded           0 Key Management Service
  15’360      0 OverwriteAsNeeded      19’094 Operations Manager
                                              Security
   8’192      0 OverwriteAsNeeded       7’012 Symantec Endpoint Protection Client
  20’480      0 OverwriteAsNeeded     102’800 System
  15’360      0 OverwriteAsNeeded      14’144 Windows PowerShell

此外,文件还指出

Get-EventLog使用已弃用的 Win32 API。结果可能不准确。请改用 `Get-WinEvent? cmdlet。

因此使用获取 WinEvent,效果很好:

Get-WinEvent -LogName "Microsoft-Windows-Ntfs/Operational"


   ProviderName: Microsoft-Windows-Ntfs

TimeCreated                     Id LevelDisplayName Message
-----------                     -- ---------------- -------
21.06.2021 01:24:48            142 Information      Summary of disk space usage, since last event:...
21.06.2021 01:24:38            142 Information      Summary of disk space usage, since last event:...
21.06.2021 01:24:38            142 Information      Summary of disk space usage, since last event:...
20.06.2021 01:24:44            142 Information      Summary of disk space usage, since last event:...

相关内容