Abstract
In this chapter, we will discuss PowerShell’s batch-job execution features, which are implemented in the form of cmdlets. At its simplest, we have the ability to run a script as a background job. However, this requires that the PowerShell session that submitted the job remains active. To avoid this constraint, we can create a scheduled job. PowerShell has a number of cmdlets to support job scheduling. As we will see, these cmdlets are really an interface to the Windows Task Scheduler. We will discuss the cmdlets that support the three components of a scheduled job: the job definition, triggers, and options. The job definition defines what code will be executed. The triggers define when the job should be executed i.e., the schedule. The options define how the job should be executed. We will wrap up the section on job cmdlets by reviewing a script that provides a simple console with which to access our PowerShell jobs. Then, we will discuss why SQL Server Agent is a better solution for job scheduling. We will step through how to create a SQL Server Agent job that executes a PowerShell script. Then, we will discuss how we can easily manipulate SQL Server Agent jobs with PowerShell. Although PowerShell’s job scheduling may not be the best solution for production, there are two good reasons we need to understand it. First, PowerShell’s job-execution and scheduling features can be very useful in development. Second, PowerShell’s remote execution and workflows use batch-execution features, so we need to understand these in order to discuss remote execution and workflows, which will be covered in the next chapter.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2015 Bryan Cafferky
About this chapter
Cite this chapter
Cafferky, B. (2015). PowerShell Jobs. In: Pro PowerShell for Database Developers. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-0541-9_12
Download citation
DOI: https://doi.org/10.1007/978-1-4842-0541-9_12
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-0542-6
Online ISBN: 978-1-4842-0541-9
eBook Packages: Professional and Applied ComputingProfessional and Applied Computing (R0)Apress Access Books