Get-JobTrigger
取得排程工作的工作觸發程式。
語法
JobDefinition (預設值)
Get-JobTrigger
[[-TriggerId] <Int32[]>]
[-InputObject] <ScheduledJobDefinition>
[<CommonParameters>]
JobDefinitionName
Get-JobTrigger
[[-TriggerId] <Int32[]>]
[-Name] <String>
[<CommonParameters>]
JobDefinitionId
Get-JobTrigger
[[-TriggerId] <Int32[]>]
[-Id] <Int32>
[<CommonParameters>]
Description
Get-JobTrigger Cmdlet 會取得排程工作的工作觸發程式。 您可以使用此命令來檢查作業觸發程式,或使用管線將作業觸發程式傳送至其他 Cmdlet。
作業觸發程式會定義啟動排程工作的週期性排程或條件。 作業觸發程式不會獨立儲存至磁碟;它們是排程工作的一部分。 若要取得作業觸發程式,請指定觸發程序啟動的排程工作。
使用 Get-JobTrigger Cmdlet 的參數來識別排程的工作。 您可以透過其名稱或識別碼來識別排程工作,或輸入或管線 ScheduledJob 物件,例如 Get-ScheduledJob Cmdlet 所傳回的物件,以 Get-JobTrigger。
Get-JobTrigger 是 Windows PowerShell 隨附的 PSScheduledJob 模組中其中一個作業排程 Cmdlet 集合。
如需排程工作的詳細資訊,請參閱 PSScheduledJob 模組中的 About 主題。
匯入 PSScheduledJob 模組,然後輸入:Get-Help about_Scheduled* 或查看about_Scheduled_Jobs。
此 Cmdlet 已在 Windows PowerShell 3.0 中引進。
範例
範例 1:依排程的作業名稱取得作業觸發程式
PS C:\> Get-JobTrigger -Name "BackupJob"
此命令會使用 Get-JobTriggerName 參數來取得 BackupJob 排程作業的作業觸發程式。
範例 2:依標識符取得作業觸發程式
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
此範例會使用 Get-JobTrigger識別子 參數來取得排程作業的作業觸發程式。
範例 3:透過管道傳送作業來取得作業觸發程式
PS C:\> Get-ScheduledJob -Name *Backup*, *Archive* | Get-JobTrigger
此命令會取得名稱中具有備份或封存之所有作業的作業觸發程式。
範例 4:取得遠端電腦上的作業觸發程式
PS C:\> Invoke-Command -ComputerName Server01 { Get-ScheduledJob Backup | Get-JobTrigger -TriggerID 2 }
此命令會取得遠端電腦上排程作業的兩個作業觸發程式之一。
此命令會使用 Invoke-Command Cmdlet 在 Server01 計算機上執行命令。 它會使用 Get-ScheduledJob Cmdlet 來取得備份排程工作,其會透過管線傳送至 get-JobTrigger Cmdlet。 它會使用 TriggerID 參數,只取得第二個觸發程式。
範例 5:取得所有作業觸發程式
PS C:\> Get-ScheduledJob | Get-JobTrigger | Format-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
此命令會取得本機電腦上所有排程工作的所有作業觸發程式。
命令會使用 Get-ScheduledJob 取得本機計算機上的排程工作,並透過管線 將工作傳送至 get-JobTrigger,這會取得每個排程工作的工作觸發程式(如果有的話)。
若要將排程工作的名稱新增至工作觸發程序顯示,命令會使用 Format-Table Cmdlet 的導出屬性功能。 除了預設顯示的作業觸發程序屬性之外,命令也會建立新的 ScheduledJob 屬性,以顯示排程工作的名稱。
範例 6:取得排程工作的工作觸發程序屬性
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}
排程作業的作業觸發程式會儲存在作業的JobTriggers屬性中。 此範例示範使用 Get-JobTrigger Cmdlet 來取得作業觸發程式的替代方案。 結果與使用 Get-JobTrigger Cmdlet 相同,而且可以交替使用技術。
範例 7:比較作業觸發程式
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 <=
此範例示範如何比較兩個排程作業的作業觸發程式。
參數
-Id
指定排程工作的識別碼。 Get-JobTrigger 取得指定排程工作的工作觸發程式。
若要取得本機電腦或遠端電腦上的排程工作識別碼,請使用 Get-ScheduledJob Cmdlet。
參數屬性
| 類型: | Int32 |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
JobDefinitionId
| Position: | 0 |
| 必要: | True |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-InputObject
指定排程的工作。 輸入包含 ScheduledJob 物件的變數,或輸入命令或表達式,以取得 ScheduledJob 物件,例如 Get-ScheduledJob 命令。 您也可以使用管線 ScheduledJob 物件,Get-JobTrigger。
參數屬性
| 類型: | ScheduledJobDefinition |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
JobDefinition
| Position: | 0 |
| 必要: | True |
| 來自管線的值: | True |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Name
指定排程工作的名稱。 Get-JobTrigger 取得指定排程工作的工作觸發程式。 支援通配符。
若要取得本機電腦或遠端電腦上的排程工作名稱,請使用 Get-ScheduledJob Cmdlet。
參數屬性
| 類型: | String |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
JobDefinitionName
| Position: | 0 |
| 必要: | True |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-TriggerId
取得指定的作業觸發程式。 輸入排程作業之一或多個作業觸發程式的觸發程式標識碼。 當 Name、識別子或 InputObj ect 參數具有多個作業觸發程式所指定的排程作業時,請使用此參數。
參數屬性
| 類型: | Int32[] |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | 1 |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
CommonParameters
此 Cmdlet 支援一般參數:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 如需詳細資訊,請參閱 about_CommonParameters。
輸入
ScheduledJobDefinition
您可以使用管線將排程工作從 Get-ScheduledJob 傳送至 Get-JobTrigger。