Clear-EventLog

清除本地或远程计算机上指定事件日志中的所有条目。

语法

Clear-EventLog
     [-LogName] <String[]>
     [[-ComputerName] <String[]>]
     [-WhatIf]
     [-Confirm]
     [<CommonParameters>]

说明

Clear-EventLog cmdlet 会删除本地计算机或远程计算机上的指定事件日志中的所有条目。 若要使用 Clear-EventLog,则必须是受影响计算机上 Administrators 组的成员。

包含 EventLog 名词的 cmdlet (EventLog 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-EventLogComputerName 参数。

Type:String[]
Aliases:Cn
Position:1
Default value:Local computer
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-Confirm

提示你在运行 cmdlet 之前进行确认。

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-LogName

指定事件日志。 输入一个或多个事件日志的日志名称(Log 属性的值;而不是 LogDisplayName),名称之间用逗号分隔。 不允许使用通配符。 此参数是必需的。

重要

此参数应按属性名称接受管道中的值。 然而,有错误阻止了此参数的工作。 必须直接使用参数传递值。

Type:String[]
Aliases:LN
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-WhatIf

显示运行该 cmdlet 时会发生什么情况。 cmdlet 未运行。

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

输入

None

不能通过管道将对象传递给 Clear-EventLog

输出

None

此 cmdlet 将不生成任何输出。

备注

  • 若要在 Windows Vista 和更高版本的 Windows 上使用 Clear-EventLog,请使用“以管理员身份运行”选项启动 Windows PowerShell。