SQL Server Agent Jobs Status from Multiple instances through powershell query
The below powershell script brings information about SQL Server Agent jobs and its status from more than one SQL Server instance.
CLEAR
$HOSTNAME='COMPUTERNAMEHERE'
Import-Module sqlps
-DisableNameChecking
$servernames=@("computername\namedinstancename1",
"computername\namedinstancename2",
"computername\namedinstancename3",
"computername\namedinstancename4",
"computername\namedinstancename5"
)
$servernames|
ForEach-Object{
$computername=$_
#Get a server
object which corresponds to the default instance
$srv=New-Object `
-TypeName 'Microsoft.SQLServer.Management.Smo.Server' `
-ArgumentList
$computername
$srv.JobServer.Jobs|
Select-Object
OriginatingServer,Name,LastRundate,LastRunOutcome,NextRunDate,CurrentRunstatus|
Where-Object
LastRunOutcome -EQ
"Failed"|
Where-Object
{$_.Name
-like "*JobNameHere*"}|
Sort-Object
LastRundate -Descending|
Format-Table
-AutoSize
}
Comments