Clear-EventLog
清除本地或远程计算机上的指定事件日志中的所有条目。
语法
Clear-EventLog
[-LogName] <String[]>
[[-ComputerName] <String[]>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
说明
Clear-EventLog
cmdlet 从本地计算机或远程计算机上的指定事件日志中删除所有条目。 若要使用 Clear-EventLog
,您必须是受影响计算机上的 Administrators 组的成员。
包含 EventLog
名词(EventLog
cmdlet)的 cmdlet 仅适用于经典事件日志。 若要从使用 Windows Vista 和更高版本的 Windows 中的 Windows 事件日志技术的日志获取事件,请使用 Get-WinEvent
cmdlet。
示例
示例 1:从本地计算机清除特定事件日志类型
Clear-EventLog "Windows PowerShell"
此命令清除本地计算机上的 Windows PowerShell 事件日志中的条目。
示例 2:清除本地和远程计算机中的特定多个日志类型
Clear-EventLog -LogName ODiag, OSession -ComputerName localhost, Server02
此命令清除本地计算机和 Server02 远程计算机上的Microsoft Office 诊断(ODiag)和Microsoft Office 会话(OSession)日志中的所有条目。
示例 3:清除指定计算机上的所有日志,然后显示事件日志列表
Clear-EventLog -LogName application, system -confirm
此命令会在删除指定事件日志中的条目之前提示你进行确认。
示例 4:清除指定计算机上的所有日志,然后显示事件日志列表
function clear-all-event-logs ($computerName="localhost")
{
$logs = Get-EventLog -ComputerName $computername -List | ForEach-Object {$_.Log}
$logs | ForEach-Object {Clear-EventLog -ComputerName $computername -LogName $_ }
Get-EventLog -ComputerName $computername -list
}
clear-all-event-logs -ComputerName Server01
Max(K) Retain OverflowAction Entries Log
------ ------ -------------- ------- ---
15,168 0 OverwriteAsNeeded 0 Application
15,168 0 OverwriteAsNeeded 0 DFS Replication
512 7 OverwriteOlder 0 DxStudio
20,480 0 OverwriteAsNeeded 0 Hardware Events
512 7 OverwriteOlder 0 Internet Explorer
20,480 0 OverwriteAsNeeded 0 Key Management Service
16,384 0 OverwriteAsNeeded 0 Microsoft Office Diagnostics
16,384 0 OverwriteAsNeeded 0 Microsoft Office Sessions
30,016 0 OverwriteAsNeeded 1 Security
15,168 0 OverwriteAsNeeded 2 System
15,360 0 OverwriteAsNeeded 0 Windows PowerShell
此函数清除指定计算机上的所有事件日志,然后显示生成的事件日志列表。
请注意,在清除日志后,会向系统和安全日志添加一些条目,但在显示日志之前。
参数
-ComputerName
指定远程计算机。 默认值为本地计算机。
键入 NetBIOS 名称、Internet 协议 (IP) 地址或远程计算机的完全限定域名。 若要指定本地计算机,请键入计算机名称、点(.
)或 localhost
。
此参数不依赖于 Windows PowerShell 远程处理。 即使计算机未配置为运行远程命令,也可以使用 Get-EventLog
ComputerName 参数。
类型: | String[] |
别名: | Cn |
Position: | 1 |
默认值: | Local computer |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-Confirm
在运行 cmdlet 之前,提示你进行确认。
类型: | SwitchParameter |
别名: | cf |
Position: | Named |
默认值: | False |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-LogName
指定事件日志。 输入日志名称(Log 属性的值,而不是一个或多个事件日志的 LogDisplayName),用逗号分隔。 不允许使用通配符。 此参数是必需的。
重要
此参数应按属性名称接受来自管道的值。 但是,存在阻止此作的 bug。 必须使用参数直接传递值。
类型: | String[] |
别名: | LN |
Position: | 0 |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-WhatIf
显示 cmdlet 运行时会发生什么情况。 cmdlet 未运行。
类型: | SwitchParameter |
别名: | wi |
Position: | Named |
默认值: | False |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
输入
None
不能通过管道将对象传递给 Clear-EventLog
。
输出
None
此 cmdlet 不生成任何输出。
备注
- 若要在 Windows Vista 和更高版本的 Windows 上使用
Clear-EventLog
,请使用 以管理员 选项启动 Windows PowerShell。