Book Image

PowerShell for SQL Server Essentials

By : Donabel Santos
Book Image

PowerShell for SQL Server Essentials

By: Donabel Santos

Overview of this book

Table of Contents (15 chapters)
PowerShell for SQL Server Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Implementing Reusability with Functions and Modules
Index

Managing jobs


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...