• opc.three (4/10/2013)


    This might help get you started:

    $Instances = (Get-Content 'C:\Instances.txt') # Make a text file containing your instances, one on each line

    [Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null

    foreach ($instance in $Instances)

    {

    $sqlServer = New-Object "Microsoft.SqlServer.Management.Smo.Server" $Instance

    $sqlAgent = $sqlServer.JobServer

    if ($sqlAgent -eq $null)

    {

    Write-Error "Could not get SMO SQL Agent object for $Instance, permissions issue?"

    }

    foreach($agentJob in $sqlAgent.Jobs)

    {

    'Name: ' + $agentJob.Name

    'CurrentRunStatus: ' + $agentJob.CurrentRunStatus

    'CurrentRunStep: ' + $agentJob.CurrentRunStep

    'LastRunDate: ' + $agentJob.LastRunDate

    }

    }

    SMO Job Class

    Very cool, Orlando. Good link, too! Book Marked.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)