0

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 が指摘したように、保持される履歴の最大行数はサーバー インスタンスによって構成されます。

ジョブ履歴の制限

4

1 に答える 1

1

エージェントが保持するように構成されている履歴の量を確認します。PowerShell では、JobServer オブジェクトの MaximumJobHistoryRows からこれを取得できます。または、SSMS でエージェントを右クリックし、「履歴」を確認します。私の推測では、ジョブごとに 100 のみを保持するように構成されていると思います。

于 2014-02-13T14:37:44.590 に答える