Skip to main content
  • 1077 Accesses

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 69.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 89.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints 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

Publish with us

Policies and ethics