【问题标题】:Why do I get this error when trying to archive the Security event log?为什么我在尝试存档安全事件日志时会收到此错误?
【发布时间】:2020-03-26 19:43:05
【问题描述】:
$EventLog = Get-WmiObject Win32_NTEventlogFile -Filter "LogFileName = 'Security'"
$Date = Get-Date -Format yyyyMMdd

$Path = "C:\Users\aamouss\Desktop\SecurityLogs"

$EventLog.BackupEventlog("$Path\$env:COMPUTERNAME`_Security_$Date.evt")

Clear-EventLog -LogName Security

我正在运行上述脚本,但出现以下错误。

您不能在空值表达式上调用方法。 在行:6 字符:1 + $EventLog.BackupEventlog("$Path\$env:COMPUTERNAME`安全$Date.evt ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

【问题讨论】:

    标签: powershell wmi event-log get-wmiobject


    【解决方案1】:

    $EventLog 是错误指示的行中唯一可能是 $null 的东西。如果我尝试执行初始化$EventLog 的命令,我发现它没有返回任何内容...

    PS> Get-WmiObject Win32_NTEventlogFile -Filter "LogFileName = 'Security'"
    PS>
    

    如果我从 Get-WmiObject 命令中删除 -Filter,这是我作为标准用户在 Windows 10 系统上看到的日志...

    PS> Get-WmiObject Win32_NTEventlogFile
    
    FileSize LogfileName            Name                                                        NumberOfRecords
    -------- -----------            ----                                                        ---------------
    15798272 Application            C:\WINDOWS\System32\Winevt\Logs\Application.evtx                      27698
       69632 HardwareEvents         C:\WINDOWS\System32\Winevt\Logs\HardwareEvents.evtx                       0
       69632 Internet Explorer      C:\WINDOWS\System32\Winevt\Logs\Internet Explorer.evtx                    0
       69632 Key Management Service C:\WINDOWS\System32\Winevt\Logs\Key Management Service.evtx               0
       69632 Parameters             C:\WINDOWS\System32\Winevt\Logs\Parameters.evtx                           0
       69632 State                  C:\WINDOWS\System32\Winevt\Logs\State.evtx                                0
    14749696 System                 C:\WINDOWS\System32\Winevt\Logs\System.evtx                           24168
    15732736 Windows PowerShell     C:\WINDOWS\System32\Winevt\Logs\Windows PowerShell.evtx               10470
    

    ...作为提升的用户...

    PS> Get-WmiObject Win32_NTEventlogFile
    
    FileSize LogfileName            Name                                                        NumberOfRecords
    -------- -----------            ----                                                        ---------------
    15798272 Application            C:\WINDOWS\System32\Winevt\Logs\Application.evtx                      27698
       69632 HardwareEvents         C:\WINDOWS\System32\Winevt\Logs\HardwareEvents.evtx                       0
       69632 Internet Explorer      C:\WINDOWS\System32\Winevt\Logs\Internet Explorer.evtx                    0
       69632 Key Management Service C:\WINDOWS\System32\Winevt\Logs\Key Management Service.evtx               0
       69632 Parameters             C:\WINDOWS\System32\Winevt\Logs\Parameters.evtx                           0
    20975616 Security               C:\WINDOWS\System32\Winevt\Logs\Security.evtx                         29714
       69632 State                  C:\WINDOWS\System32\Winevt\Logs\State.evtx                                0
    14749696 System                 C:\WINDOWS\System32\Winevt\Logs\System.evtx                           24170
    15732736 Windows PowerShell     C:\WINDOWS\System32\Winevt\Logs\Windows PowerShell.evtx               10477
    

    请注意,Security 日志仅在 cmdlet 以提升权限运行时可用。因此,如果我以提升的用户身份运行原始命令,它能够访问Security 日志...

    PS> Get-WmiObject Win32_NTEventlogFile -Filter "LogFileName = 'Security'"
    
    FileSize LogfileName Name                                          NumberOfRecords
    -------- ----------- ----                                          ---------------
    20975616 Security    C:\WINDOWS\System32\Winevt\Logs\Security.evtx           29723
    

    来自Event Logging Security...

    Security 日志专为系统使用而设计。但是,如果用户被授予SE_SECURITY_NAME 权限(“管理审计和安全日志”用户权限),则用户可以读取和清除Security 日志。

    【讨论】:

      猜你喜欢
      • 2020-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-15
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 2016-01-01
      相关资源
      最近更新 更多