包含EventLog名词(EventLogcmdlet)的 cmdlet 仅适用于经典事件日志。 若要从 Windows Vista 和更高版本的 Windows作系统中使用 Windows 事件日志技术的日志获取事件,请使用Get-WinEventcmdlet。 示例 示例1:将事件写入应用程序事件日志 PowerShell PS C:\>Write-EventLog-LogName"Application"-Source"MyApp"-EventID30...
Write-EventLog和System.Diagnostics.EventLog区别 Write-EventLog和New-Object System.Diagnostics.EventLog是两种不同的方法来写入日志。以下是它们之间的主要区别: Write-EventLog是PowerShell中的一个内置命令,用于写入事件日志。它提供了一个简单的方法来写入事件日志,不需要额外的代码。它可以直接在PowerShell脚本中使...
Write-Eventlog –LogName Application –Source 'My-App' –EntryType Error –EventID 10999 -Message 'This is test error. Please Ignore'Write-Eventlog : The source name "My-App" does not exist on computer "localhost".At line:1 char:1+ Write-Eventlog –LogName Application –Sou...
Write-Host "$Eventlog_source is already registered with another Eventlog." Exit } #新建事件日志MyApp,指定事件日志来源为$Eventlog_log,"."代表本机;将变量$ Event_test中的内容写入到MyApp事件日志下 $Applog = New-Object system.diagnostics.eventlog($Eventlog_log,".") #Remove-Eventlog $log #...
ComputerName Write eventlog entries of this log CurrentPSTransaction Gets an object that surfaces the current PowerShell transaction. When this object is disposed, PowerShell resets the active transaction. (Inherited from Cmdlet) EntryType String which represents One of the EventLogEntryType value...
默认写入的是Information级别的Log。如果想要制定Level,就要加上EntryType参数: write-eventLog -LogName Game -Message "GayShyFool invoked 'My Dad is a Gang' method." -Source CS -id 2-EntryType Warning 要直接在PowerShell里面读取EventLog,用的是get-eventlog命令:get-eventlog-LogName Game -Source CS...
$Applog.source = $Eventlog_source $Event_test = "PS Test for powershell to write." $Applog.writeEntry($Event_test) 之上输出的事件日志默认级别为“Information”,除此之外还有“Error”、“Warning”、“ SuccessAudit”和“FailureAudit”几种级别。
$applog.source = "ps_script" $applog.writeEntry("test for script write applog") 在该脚本中调用来源需要首先确定是否已经定义此来源并关联了事件日志,为此需要执行非运算。在来源没有定义的情况下进行容错处理,即在来源不存在的情况下创建一个指定来源名的来源。由于在脚本中用system.diagnostics.eventlog类的...
write-EventLog 应用: PS C:\>write-eventlog -computername Server01 -logname Application -source MyApp -eventID 3001 -message "MyApp added a user-requested feature to the display." 此命令将一个事件从 MyApp 源写入远程计算机 Server01 上的应用程序事件日志。
Limit-EventLog New-EventLog Remove-EventLog Show-EventLog Write-EventLog 常见的日志操作 下面介绍一下Powershell中常见的事件日志操作 列出事件日志列表 Get-Eventlog -List 查看security日志 Get-Eventlog -LogName security 列出最近日志 Get-EventLog -LogName security -Newest 5 列出指定时间段内的日志 Get-...