Created
February 21, 2013 05:52
-
-
Save azechi/d7679556ab26a4375f6d to your computer and use it in GitHub Desktop.
windows 2003 のイベントログ ローテーション
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# windows 2003 向けのイベントログローテーションタスク | |
param($logname="[logname]", $backupFolder=(&{Split-Path $MyInvocation.ScriptName})) | |
$logfiles = Get-WmiObject win32_nteventlogfile -Filter "LogfileName='$logname'" -EnableAllPrivileges | |
if ($logfiles -eq $null) | |
{ | |
throw "ログファイル $logname は存在しません。" | |
} | |
&{ | |
$ErrorActionPreference = "stop" | |
if (! (Test-Path $backupFolder)) | |
{ | |
$null = mkdir $backupFolder | |
} | |
} | |
foreach( $log in $logfiles) | |
{ | |
$dest = "$backupFolder\{0:yyyyMMddHHmm}_{1}.evt" -f [datetime]::Now, $log.LogfileName | |
$ret = $log.ClearEventlog($dest) | |
if($ret -eq 0) | |
{ | |
throw "ClearEventLogが失敗しました。$ret, $logname, $backupFolder, $dest" | |
# 0:成功 | |
# 8:特権がない | |
# 21:パラメーターが無効 | |
# 183: 保存先ファイル名は既に存在する | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment