Clear-EventLog
在本機或遠端電腦上刪除特定事件記錄檔的所有記錄。
語法
Clear-EventLog [-LogName] <string[]> [[-ComputerName] <string[]>] [-Confirm] [-WhatIf] [<CommonParameters>]
描述
Clear-EventLog Cmdlet 會在本機或遠端電腦上刪除特定事件記錄檔的所有記錄。若要使用 Clear-EventLog,那麼在受影響的電腦上,您必須是 Administrators 群組的成員。
有 EventLog 名詞的 Cmdlet (EventLog Cmdlet) 只適用於傳統事件記錄檔。若要在 Windows Vista 和較新版本的 Windows 上,從使用 Windows 事件記錄檔技術的記錄檔中取得事件,請使用 Get-WinEvent。
參數
-ComputerName <string[]>
指定遠端電腦。預設為本機電腦。
請輸入遠端電腦的 NetBIOS 名稱、網際網路通訊協定 (IP) 位址或完整網域名稱。若要指定本機電腦,請輸入電腦名稱、句點 (.) 或 "localhost"。
此參數並不依存於 Windows PowerShell 遠端。即使沒有將電腦設定成執行遠端命令,也可以使用 Get-EventLog 的 ComputerName 參數。
必要? |
false |
位置? |
2 |
預設值 |
本機電腦 |
接受管線輸入? |
true (ByPropertyName) |
接受萬用字元? |
false |
-LogName <string[]>
指定事件記錄檔。輸入一個或多個事件記錄檔的記錄檔名稱 (是 Log 屬性的值,而非 LogDisplayName),以逗號分隔。不允許使用萬用字元。此參數為必要項。
必要? |
true |
位置? |
1 |
預設值 |
|
接受管線輸入? |
true (ByPropertyName) |
接受萬用字元? |
false |
-Confirm
在執行命令前先提示確認。
必要? |
false |
位置? |
named |
預設值 |
|
接受管線輸入? |
false |
接受萬用字元? |
false |
-WhatIf
說明執行命令時將會發生何種情況,但不會實際執行命令。
必要? |
false |
位置? |
named |
預設值 |
|
接受管線輸入? |
false |
接受萬用字元? |
false |
<CommonParameters>
這個 Cmdlet 支援一般參數:-Verbose、-Debug、-ErrorAction、-ErrorVariable、-OutBuffer 和 -OutVariable。如需詳細資訊,請參閱 about_Commonparameters.
輸入和輸出
輸入型別是可經由管道輸出至 Cmdlet 的物件型別。傳回型別則是 Cmdlet 所傳回的物件型別。
輸入 |
無 您無法經由管道將物件輸出至 Clear-EventLog。 |
輸出 |
無 這個 Cmdlet 不會產生任何輸出。 |
附註
若要在 Windows Vista 與較新版本的 Windows 上使用 Clear-EventLog,請以 [以系統管理員身分執行] 選項啟動 Windows PowerShell。
範例 1
C:\PS>clear-eventlog "Windows PowerShell"
描述
-----------
這個命令會在本機電腦上刪除 "Windows PowerShell" 事件記錄檔的記錄。
範例 2
C:\PS>clear-eventlog -logname ODiag, OSession -computername localhost, Server02
描述
-----------
這個命令會在本機電腦與 Server02 遠端電腦上,刪除 Microsoft Office Diagnostics (ODiag) 與 Microsoft Office Sessions (OSession) 記錄檔中的所有記錄。
範例 3
C:\PS>clear-eventlog -log application, system -confirm
描述
-----------
這個命令會先提示您進行確認,然後再刪除特定事件記錄檔中的記錄。
範例 4
C:\PS>function clear-all-event-logs ($computerName="localhost")
{
$logs = get-eventlog -computername $computername -list | foreach {$_.Log}
$logs | foreach {clear-eventlog -comp $computername -log $_ }
get-eventlog -computername $computername -list
}
C:\PS> clear-all-event-logs -comp 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
描述
-----------
這個函數會刪除特定電腦上的所有事件記錄檔,然後顯示產生的事件記錄檔清單。
請注意,在記錄檔清除後但在顯示記錄檔之前,會有幾筆記錄加入 System 與 Security 記錄檔中。
請參閱
概念
Get-EventLog
Limit-EventLog
New-EventLog
Remove-EventLog
Show-EventLog
Write-EventLog
Get-WinEvent