Powershell 为什么在尝试存档安全事件日志时会出现此错误? $EventLog=Get WmiObject Win32\u NTEventlogFile-Filter“LogFileName=‘Security’” $Date=获取日期-格式yyyyMMdd $Path=“C:\Users\aamous\Desktop\SecurityLogs” $EventLog.BackupEventlog($Path\$env:COMPUTERNAME`\u Security\$Date.evt) 清除事件日志-日志名安全性
我正在运行上面的脚本,但得到下面的错误 不能对空值表达式调用方法。 第6行字符:1 +$EventLog.BackupEventlog(“$Path\$env:COMPUTERNAME`Security$Date.evt…”。。。 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CategoryInfo:InvalidOperation:(:)[],运行时异常 +FullyQualifiedErrorId:InvokeMethodOnFullPowershell 为什么在尝试存档安全事件日志时会出现此错误? $EventLog=Get WmiObject Win32\u NTEventlogFile-Filter“LogFileName=‘Security’” $Date=获取日期-格式yyyyMMdd $Path=“C:\Users\aamous\Desktop\SecurityLogs” $EventLog.BackupEventlog($Path\$env:COMPUTERNAME`\u Security\$Date.evt) 清除事件日志-日志名安全性,powershell,wmi,event-log,get-wmiobject,Powershell,Wmi,Event Log,Get Wmiobject,我正在运行上面的脚本,但得到下面的错误 不能对空值表达式调用方法。 第6行字符:1 +$EventLog.BackupEventlog(“$Path\$env:COMPUTERNAME`Security$Date.evt…”。。。 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CategoryInfo:InvalidOperation:(:)[],运行时异常 +FullyQualifiedErro
$EventLog
是错误指示行中唯一可以是$null
的内容。如果我尝试执行初始化$EventLog
的命令,我发现它不会返回任何内容
PS>Get WmiObject Win32\u NTEventlogFile-Filter“LogFileName=‘Security’”
PS>
如果我从获取WmiObject
命令中删除-Filter
,以下是我作为标准用户在Windows 10系统上看到的日志
PS>获取WmiObject Win32\u NTEventlogFile
FileSize日志文件名Name NumberOfRecords
-------- ----------- ---- ---------------
15798272应用程序C:\WINDOWS\System32\Winevt\Logs\Application.evtx 27698
69632硬件事件C:\WINDOWS\System32\Winevt\Logs\HardwareEvents.evtx 0
69632 Internet Explorer C:\WINDOWS\System32\Winevt\Logs\Internet Explorer.evtx 0
69632密钥管理服务C:\WINDOWS\System32\Winevt\Logs\Key Management Service.evtx 0
69632参数C:\WINDOWS\System32\Winevt\Logs\Parameters.evtx 0
69632状态C:\WINDOWS\System32\Winevt\Logs\State.evtx 0
14749696系统C:\WINDOWS\System32\Winevt\Logs\System.evtx 24168
15732736 Windows PowerShell C:\Windows\System32\Winevt\Logs\Windows PowerShell.evtx 10470
…作为一个高级用户
PS>获取WmiObject Win32\u NTEventlogFile
FileSize日志文件名Name NumberOfRecords
-------- ----------- ---- ---------------
15798272应用程序C:\WINDOWS\System32\Winevt\Logs\Application.evtx 27698
69632硬件事件C:\WINDOWS\System32\Winevt\Logs\HardwareEvents.evtx 0
69632 Internet Explorer C:\WINDOWS\System32\Winevt\Logs\Internet Explorer.evtx 0
69632密钥管理服务C:\WINDOWS\System32\Winevt\Logs\Key Management Service.evtx 0
69632参数C:\WINDOWS\System32\Winevt\Logs\Parameters.evtx 0
20975616安全C:\WINDOWS\System32\Winevt\Logs\Security.evtx 29714
69632状态C:\WINDOWS\System32\Winevt\Logs\State.evtx 0
14749696系统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\u NTEventlogFile-Filter“LogFileName=‘Security’”
FileSize日志文件名Name NumberOfRecords
-------- ----------- ---- ---------------
20975616安全C:\WINDOWS\System32\Winevt\Logs\Security.evtx 29723
从
Security
日志是为系统使用而设计的。但是,如果用户被授予了seu Security\u NAME
权限(“管理审核和安全日志”用户权限),则可以读取和清除Security
日志
$EventLog
是错误指示行中唯一可以是$null
的内容。如果我尝试执行初始化$EventLog
的命令,我发现它不会返回任何内容
PS>Get WmiObject Win32\u NTEventlogFile-Filter“LogFileName=‘Security’”
PS>
如果我从获取WmiObject
命令中删除-Filter
,以下是我作为标准用户在Windows 10系统上看到的日志
PS>获取WmiObject Win32\u NTEventlogFile
FileSize日志文件名Name NumberOfRecords
-------- ----------- ---- ---------------
15798272应用程序C:\WINDOWS\System32\Winevt\Logs\Application.evtx 27698
69632硬件事件C:\WINDOWS\System32\Winevt\Logs\HardwareEvents.evtx 0
69632 Internet Explorer C:\WINDOWS\System32\Winevt\Logs\Internet Explorer.evtx 0
69632密钥管理服务C:\WINDOWS\System32\Winevt\Logs\Key Management Service.evtx 0
69632参数C:\WINDOWS\System32\Winevt\Logs\Parameters.evtx 0
69632状态C:\WINDOWS\System32\Winevt\Logs\State.evtx 0
14749696系统C:\WINDOWS\System32\Winevt\Logs\System.evtx 24168
15732736温多