Изменение парамтров журнала событий
function DisplayLogSettings()
{
Write-Host `
"
The current settings on the $($objlog.LogDisplayName) file are:
max kilobytes: $($objLog.maximumKiloBYtes)
min retention days: $($objLog.minimumRetentionDays)
overflow policy: $($objLog.overFlowAction)
"
if (!$args) { ChangeLogSettings("help") }
}
function ChangeLogSettings($policy)
{ if($policy -ne "help")
{
Write-Host -ForegroundColor green "changing log policy ..."
}
switch($policy)
{
"doNotOW" { $objlog.modifyoverflowpolicy("DoNotOverwrite",-1) }
"owAsNeeded" { $objlog.modifyoverflowpolicy("OverwriteAsNeeded",-1) }
"owOlder" { $objlog.modifyoverflowpolicy("Overwriteolder",$intRetention) }
DEFAULT {
Write-Host -ForegroundColor red `
"
Необходимо задать один из следующих варинтов: `n
doNotOW - не перезаписывать журналы
owAsNeeded - Затирать старые по необходимости
owOlder - Затирать старые события, хранящеейся более $intRetention дней `n
Example: > SetEventLogRetentionPolicy.ps1 doNotOW
Sets retention policy to Do not Overwrite
Example: > SetEventLogRetentionPolicy.ps1 owAsNeeded
Sets retention policy to Overwrite as needed
Example: > SetEventLogRetentionPolicy.ps1 owOlder
Sets retention policy to Overwrite older than 30 days
Example: > SetEventLogRetentionPolicy.ps1 help
Displays this help message
"
exit }
}
}
$strLog = "application" #modify for different log
$intRetention = 30 #modify for different number of retention days
$objLog = New-Object system.diagnostics.eventlog("$strLog")
DisplayLogSettings($args)
ChangeLogSettings($args)
DisplayLogSettings($args)
Голосов пока нет

Оставить комментарий