You can list information on the current job server and the related jobs. Once the SMO server is set up, you can list the properties by using the following command:
$server.JobServer | Select-Object *
A long list of properties will be displayed. A partial list looks like the following screenshot:
Notice that information on the job server includes the service account, job categories, alerts, operators, jobs, proxy accounts, and shared schedules.
To list details about the jobs, you can use the same JobServer
object and iterate over all the jobs in that collection. Each SMO Job
object contains information about the job name, last run date, last run outcome, and each step's individual outcome. A sample script that lists the job details is as follows:
Import-Module SQLPS -DisableNameChecking #current server name $servername = "ROGUE" # or localhost $server = New-Object "Microsoft.SqlServer.Management.Smo.Server" $servername $result = @() $server.JobServer.Jobs | Foreach-Object...