SQL メンテナンス タスクの失敗をスキャンするスクリプトを作成しようとしています。以下のスクリプトを参照してください。EnumHistory() を使用して 100 を超えるエントリを処理できないようです。誰もこれを回避する方法を持っていますか?
Param(
[int]$days="30" # this hardly matters since EnumJobHistory is limited to 100 rows :-(
)
#http://powershell.com/cs/blogs/tobias/archive/2010/01/13/cancelling-a-pipeline.aspx
filter Stop-Pipeline([scriptblock]$condition = {$true})
{$_
if (& $condition) {continue}
}
cls
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
$instances = Get-Content "DailyMaintenanceMMCServerList.txt"
#loop through each instance
foreach ($instance in $instances)
{
# Create an SMO connection to the instance
$srv = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $instance
$instance
#get all the jobs on the server
$jobs = $srv.JobServer.Jobs
# Avoid exception on some servers?
if (!$jobs.Count)
{
continue
}
#go through each job and find failures in the job history
$jobs | % {
do
{ $job = $_; $count = 0;
$_.EnumHistory() |
Stop-Pipeline { $_.Rundate -lt [datetime]::Today.AddDays(-$days) } |
#? {$_.Message -notlike "*succeeded*" } |
% { " " + ++$count + " " + $job.Name + " " + $_.RunDate + " " + ($_.Message).Substring(0,20) }
} while ($false)
}
}
Ben Thul が指摘したように、保持される履歴の最大行数はサーバー インスタンスによって構成されます。
