locked
Powershell sql agent jobs RRS feed

  • Question

  • Hi, I am trying to check status of sql agent jobs on various servers using powershell howerver I successfully list all the servers but cant seem to be able to Write-Output $job.name for any of the servers including the monitoring server that I am absolutely sure I have all required permissions. I get no errors which makes troubleshooting that much more difficult. Any ideas? Thank you

    ...

     foreach($sqlserver in $sqlservers)

    {

    #***THIS WORKS***

    write-host $sqlserver.instancename

    $srv = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $sqlserver;

    foreach ($job in $srv.Jobserver.Jobs)

    {

    $jobName = $job.Name;

    $jobEnabled = $job.IsEnabled;

    ...

    #***THIS DOESN'T WORK***

    write-host  $jobName 

    write-host  $job.Name 

    ...


    Paula


    • Edited by ptt2014 Monday, November 3, 2014 7:23 PM
    Monday, November 3, 2014 7:17 PM

Answers

  • I figured it out

    The  line

    $srv = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $sqlserver;

    should be:

     $srv = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $sqlserver.InstanceName ;


    Paula

    • Marked as answer by ptt2014 Tuesday, November 4, 2014 2:36 PM
    Tuesday, November 4, 2014 2:36 PM