Get-JobTrigger
Published: February 29, 2012
Updated: August 22, 2012
Applies To: Windows PowerShell 3.0
Get-JobTrigger
Syntax
Parameter Set: JobDefinition Get-JobTrigger [-InputObject] <ScheduledJobDefinition> [[-TriggerId] <Int32[]> ] [ <CommonParameters>] Parameter Set: JobDefinitionId Get-JobTrigger [-Id] <Int32> [[-TriggerId] <Int32[]> ] [ <CommonParameters>] Parameter Set: JobDefinitionName Get-JobTrigger [-Name] <String> [[-TriggerId] <Int32[]> ] [ <CommonParameters>]
Detailed Description
The Get-JobTrigger cmdlet gets the job triggers of scheduled jobs. You can use this command to examine the job triggers or to pipe the job triggers to other cmdlets.
A "job trigger" defines a recurring schedule or conditions for starting a scheduled job. Job triggers are not saved to disk independently; they are part of a scheduled job. To get a job trigger, specify the scheduled job that the trigger starts.
Use the parameters of the Get-JobTrigger cmdlet to identify the scheduled jobs. You can identify the scheduled jobs by their names or identification numbers, or by entering or piping ScheduledJob objects, such as the those that are returned by the Get-ScheduledJob cmdlet, to Get-JobTrigger.
Get-JobTrigger is one of a collection of job scheduling cmdlets in the PSScheduledJob module that is included in Windows PowerShell.
This cmdlet is introduced in Windows PowerShell 3.0.
Parameters
-Id<Int32>
Specifies the identification number of a scheduled job. Get-JobTrigger gets the job trigger of the specified scheduled job.
To get the identification number of scheduled jobs on the local computer or a remote computer, use the Get-ScheduledJob cmdlet.
|
Aliases |
none |
|
Required? |
true |
|
Position? |
1 |
|
Default Value |
none |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
-InputObject<ScheduledJobDefinition>
Specifies a scheduled job. Enter a variable that contains ScheduledJob objects or type a command or expression that gets ScheduledJob objects, such as a Get-ScheduledJob command. You can also pipe ScheduledJob objects to Get-JobTrigger.
|
Aliases |
none |
|
Required? |
true |
|
Position? |
1 |
|
Default Value |
none |
|
Accept Pipeline Input? |
true (ByValue) |
|
Accept Wildcard Characters? |
false |
-Name<String>
Specifies the name of a scheduled job. Get-JobTrigger gets the job trigger of the specified scheduled job. Wildcards are supported.
To get the names of scheduled jobs on the local computer or a remote computer, use the Get-ScheduledJob cmdlet.
|
Aliases |
none |
|
Required? |
true |
|
Position? |
1 |
|
Default Value |
None |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
true |
-TriggerId<Int32[]>
Gets the specified job triggers. Enter the trigger IDs of one or more job triggers of a scheduled job. Use this parameter when the scheduled job that is specified by the Name, ID, or InputObject parameters has multiple job triggers.
|
Aliases |
none |
|
Required? |
false |
|
Position? |
2 |
|
Default Value |
none |
|
Accept Pipeline Input? |
false |
|
Accept Wildcard Characters? |
false |
<CommonParameters>
This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).
Inputs
The input type is the type of the objects that you can pipe to the cmdlet.
-
Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition
You can pipe a scheduled job from Get-ScheduledJob to Get-JobTrigger.
Outputs
The output type is the type of the objects that the cmdlet emits.
- Microsoft.PowerShell.ScheduledJob.ScheduledJobTrigger
Examples
Example 1: Get a job trigger by scheduled job name
The command uses the Name parameter of Get-JobTrigger to get the job triggers of the BackupJob scheduled job.
PS C:\> Get-JobTrigger -Name BackupJob
Example 2: Get a job trigger by ID
The example uses the ID parameter of Get-JobTrigger to get the job triggers of a scheduled job.
The first command uses the Get-ScheduledJob cmdlet to display the scheduled jobs on the local computer. The display includes the IDs of the scheduled jobs.
PS C:\> Get-ScheduledJob
Id Name Triggers Command Enabled
-- ---- -------- ------- -------
1 ArchiveProjects {1} \\Server\Share\Archive-Projects.ps1 True
2 Backup {1,2} \\Server\Share\Run-Backup.ps1 True
3 Test-HelpFiles {1} \\Server\Share\Test-HelpFiles.ps1 True
4 TestJob {} \\Server\Share\Run-AllTests.ps1 True
The second command uses the Get-JobTrigger cmdlet to get the job trigger for the Test-HelpFiles job (ID = 3)
PS C:\> Get-JobTrigger -ID 3
Example 3: Get job triggers by piping a job
This command gets the job triggers of all jobs that have "Backup" or "Archive" in their names.
PS C:\> Get-ScheduledJob -Name *Backup*, *Archive* | Get-JobTrigger
Example 4: Get the job trigger of a job on a remote computer
This command gets one of the two job triggers of a scheduled job on a remote computer.
The command uses the Invoke-Command cmdlet to run a command on the Server01 computer. It uses the Get-ScheduledJob cmdlet to get the Backup scheduled job, which it pipes to the Get-JobTrigger cmdlet. It uses the TriggerID parameter to get only the second trigger.
PS C:\> Invoke-Command -ComputerName Server01 { Get-ScheduledJob Backup | Get-JobTrigger -TriggerID 2 }
Example 5: Get all job triggers
This command gets all job triggers of all scheduled jobs on the local computer.
The command uses the Get-ScheduledJob to get the scheduled jobs on the local computer and pipes them to Get-JobTrigger, which gets the job trigger of each scheduled job (if any).
To add the name of the scheduled job to the job trigger display, the command uses the "calculated property" feature of the Format-Table cmdlet. In addition to the job trigger properties that are displayed by default, the command creates a new "ScheduledJob" property that displays the name of the scheduled job.
PS C:\> Get-ScheduledJob | Get-JobTrigger | For mat-Table -Property ID, Frequency, At, DaysOfWeek, Enabled, @{Label="ScheduledJob";Expression={$_.JobDefinition.Name}} -AutoSize
Id Frequency At DaysOfWeek Enabled ScheduledJob
-- --------- -- ---------- ------- ------------
1 Weekly 9/28/2011 3:00:00 AM {Monday} True Backup
1 Daily 9/27/2011 11:00:00 PM True Test-HelpFiles
Example 6: Get the job trigger property of a scheduled job
The job triggers of a scheduled job are stored in the JobTriggers property of the job. This example shows alternatives to using the Get-JobTrigger cmdlet to get job triggers. The results are identical to using the Get-JobTrigger cmdlet and the techniques can be used interchangeably.
The command uses the Get-ScheduledJob cmdlet to get the Test-HelpFiles scheduled job. Then it uses the dot method (.) to get the JobTriggers property of the Test-HelpFiles scheduled job.
PS C:\> (Get-ScheduledJob Test-HelpFiles).JobTriggers
The second command uses the Get-ScheduledJob cmdlet to get all scheduled jobs on the local computer. It uses the Foreach-Object cmdlet to get the value of the JobTrigger property of each scheduled job.
PS C:\> Get-ScheduledJob | foreach {$_.JobTriggers}
Example 7: Compare job triggers
This example shows how to compare the job triggers of two scheduled jobs.
The first command gets the job trigger of the ArchiveProjects scheduled job. The command pipes the job trigger to the Tee-Object cmdlet, which saves the job trigger in the $t1 variable and displays it at the command line.
PS C:\> Get-ScheduledJob -Name ArchiveProjects | Get-JobTrigger | Tee-Object -Variable t1
Id Frequency Time DaysOfWeek Enabled
-- --------- ---- ---------- -------
0 Daily 9/26/2011 3:00:00 AM True
The second command gets the job trigger of the Test-HelpFiles scheduled job. The command pipes the job trigger to the Tee-Object cmdlet, which saves the job trigger in the $t2 variable and displays it at the command line.
PS C:\> Get-ScheduledJob -Name Test-HelpFiles | Get-JobTrigger | Tee-Object -Variable t2
Id Frequency Time DaysOfWeek Enabled
-- --------- ---- ---------- -------
0 Daily 9/26/2011 3:00:00 AM True
The third command compares the job triggers in the $t1 and $t2 variables. It uses the Get-Member cmdlet to get the properties of the job trigger in the $t1 variable. It pipes the properties to the ForEach-Object cmdlet, which compares each property to the properties of the job trigger in the $t2 variable by name. The command then pipes the differing properties to the Format-List cmdlet, which displays them in a list.
The output indicates that, although the job triggers appear to be the same, the HelpFiles job trigger includes a random delay of three (3) minutes.
PS C:\> $t1 | Get-Member -Type property | ForEach-Object { Compare-Object $t1 $t2 -Property $_.Name}
RandomDelay SideIndicator
----------- -------------
00:00:00 =>
00:03:00 <=
Related topics
about_Scheduled_Jobs
Add-JobTrigger
Disable-JobTrigger
Disable-ScheduledJob
Enable-JobTrigger
Enable-ScheduledJob
Get-JobTrigger
Get-ScheduledJob
Get-ScheduledJobOption
New-JobTrigger
New-ScheduledJobOption
Register-ScheduledJob
Remove-JobTrigger
Set-JobTrigger
Set-ScheduledJob
Set-ScheduledJobOption
Unregister-ScheduledJob