Limit-EventLog
設定事件記錄檔屬性,該屬性會限制事件記錄檔的大小以及記錄的使用期限。
語法
Limit-EventLog [-LogName] <string[]> [-ComputerName <string[]>] [-MaximumSize <Int64>] [-OverFlowAction {<OverwriteAsNeeded> | <OverwriteOlder> | <DoNotOverwrite>}] [-RetentionDays <int>] [-Confirm] [-WhatIf] [<CommonParameters>]
描述
Limit-EventLog Cmdlet 設定傳統事件記錄檔的大小上限、每一個事件必須保持的長度,以及記錄檔到達大小上限時會發生的狀況。您可以利用這個 Cmdlet 限制本機或遠端電腦上的事件記錄檔。
有 EventLog 名詞的 Cmdlet (EventLog Cmdlet) 只適用於傳統事件記錄檔。若要在 Windows Vista 和較新版本的 Windows 上,從使用 Windows 事件記錄檔技術的記錄檔中取得事件,請使用 Get-WinEvent。
參數
-ComputerName <string[]>
指定遠端電腦。預設為本機電腦。
請輸入遠端電腦的 NetBIOS 名稱、網際網路通訊協定 (IP) 位址或完整網域名稱。若要指定本機電腦,請輸入電腦名稱、句點 (.) 或 "localhost"。
此參數並不依存於 Windows PowerShell 遠端。即使沒有將電腦設定成執行遠端命令,也可以使用 Limit-EventLog 的 ComputerName 參數。
必要? |
false |
位置? |
named |
預設值 |
本機電腦 |
接受管線輸入? |
false |
接受萬用字元? |
false |
-LogName <string[]>
指定事件記錄檔。輸入一個或多個事件記錄檔的記錄名稱 (是 Log 屬性的值、而非 LogDisplayName),以逗號分隔。不允許使用萬用字元。此參數為必要項。
必要? |
true |
位置? |
1 |
預設值 |
無 |
接受管線輸入? |
false |
接受萬用字元? |
false |
-MaximumSize <Int64>
指定事件記錄檔的大小上限,以位元組為單位。輸入介於 64 KB 到 4 GB 之間的值。該值必須可以由 64 KB (65536) 整除。
這個參數指定 System.Diagnostics.EventLog (表示傳統事件記錄檔) 物件的 MaximumKilobytes 屬性值。
必要? |
false |
位置? |
named |
預設值 |
無 |
接受管線輸入? |
false |
接受萬用字元? |
false |
-OverFlowAction <OverflowAction>
指定事件記錄檔的大小達到上限時會發生的狀況。
有效的值包括:
-- DoNotOverwrite: 保留現有的記錄並捨棄新記錄。
-- OverwriteAsNeeded: 每一筆新記錄都會覆寫最舊的記錄。
-- OverwriteOlder: 新事件覆寫早於 MinimumRetentionDays 屬性所指定的值。如果沒有早於 MinimumRetentionDays 屬性所指定之值的事件,則會捨棄新事件。
這個參數指定 System.Diagnostics.EventLog (表示傳統事件記錄檔) 物件的 OverflowAction 屬性值。
必要? |
false |
位置? |
named |
預設值 |
無 |
接受管線輸入? |
false |
接受萬用字元? |
false |
-RetentionDays <int>
指定事件必須保留在事件記錄檔中的最少天數。
這個參數指定 System.Diagnostics.EventLog (表示傳統事件記錄檔) 物件的 MinimumRetentionDays 屬性值。
必要? |
false |
位置? |
named |
預設值 |
無 |
接受管線輸入? |
false |
接受萬用字元? |
false |
-Confirm
在執行命令前先提示確認。
必要? |
false |
位置? |
named |
預設值 |
|
接受管線輸入? |
false |
接受萬用字元? |
false |
-WhatIf
說明執行命令時將會發生何種情況,但不會實際執行命令。
必要? |
false |
位置? |
named |
預設值 |
|
接受管線輸入? |
false |
接受萬用字元? |
false |
<CommonParameters>
這個 Cmdlet 支援一般參數:-Verbose、-Debug、-ErrorAction、-ErrorVariable、-OutBuffer 和 -OutVariable。如需詳細資訊,請參閱 about_Commonparameters.
輸入和輸出
輸入型別是可經由管道輸出至 Cmdlet 的物件型別。傳回型別則是 Cmdlet 所傳回的物件型別。
輸入 |
無 無 |
輸出 |
無 無 |
附註
若要在 Windows Vista 與較新版本的 Windows 上使用 Limit-EventLog,請以 [以系統管理員身分執行] 選項開啟 Windows PowerShell。
Limit-EventLog 變更 System.Diagnostics.EventLog 物件 (表示傳統事件記錄檔) 的屬性。若要檢視事件記錄檔屬性的目前設定,請輸入 "Get-EventLog -list"。
範例 1
C:\PS>limit-eventLog -logname "Windows PowerShell" -MaximumSize 20KB
描述
-----------
這個命令會將本機電腦上的 Windows PowerShell 事件記錄檔大小上限增加到 20480 位元組 (20 KB)。
範例 2
C:\PS>limit-eventlog -logname Security -comp Server01, Server02 -retentionDays 7
描述
-----------
這個命令可以確保 Server01 與 Server02 電腦上 Security 記錄檔中的事件至少保留 7 天。
範例 3
C:\PS>$logs = get-eventlog -list | foreach {$_.log}
C:\PS> limit-eventlog -overflowaction OverwriteOlder -logname $logs
C:\PS> get-eventlog -list
Max(K) Retain OverflowAction Entries Log
------ ------ -------------- ------- ---
15,168 0 OverwriteOlder 3,412 Application
512 0 OverwriteOlder 0 DFS Replication
512 0 OverwriteOlder 17 DxStudio
10,240 7 OverwriteOlder 0 HardwareEvents
512 0 OverwriteOlder 0 Internet Explorer
512 0 OverwriteOlder 0 Key Management Service
16,384 0 OverwriteOlder 4 ODiag
16,384 0 OverwriteOlder 389 OSession
Security
15,168 0 OverwriteOlder 19,360 System
15,360 0 OverwriteOlder 15,828 Windows PowerShell
描述
-----------
這些命令將本機電腦上所有事件記錄檔的溢位動作變更為 "OverwriteOlder"。
第一個命令取得本機電腦上的所有記錄檔的記錄檔名稱。第二個命令設定溢位動作。第三個命令顯示結果。
請參閱
概念
Clear-EventLog
Get-EventLog
Limit-EventLog
New-EventLog
Remove-EventLog
Show-EventLog
Write-EventLog
Get-WinEvent