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

说明

Get-JobTrigger cmdlet 获取计划作业的作业触发器。 可以使用此命令检查作业触发器或将作业触发器通过管道传递给其他 cmdlet。

作业触发器定义用于启动计划作业的定期计划或条件。 作业触发器不会单独保存到磁盘;它们是计划作业的一部分。 若要获取作业触发器,请指定触发器启动的计划作业。

使用 Get-JobTrigger cmdlet 的参数来标识计划的作业。 可以通过计划作业的名称或标识号,或通过输入或管道 ScheduledJob 对象(例如由 Get-ScheduledJob cmdlet 返回的作业)来 Get-JobTrigger

Get-JobTrigger 是 PSScheduledJob 模块中包含的作业计划 cmdlet 集合之一。

有关计划作业的详细信息,请参阅 PSScheduledJob 模块中的“关于”主题。 导入 PSScheduledJob 模块,然后键入:Get-Help about_Scheduled* 或查看about_Scheduled_Jobs。

此 cmdlet 已在 Windows PowerShell 3.0 中引入。

示例

示例 1:按计划作业名称获取作业触发器

PS C:\> Get-JobTrigger -Name "BackupJob"

该命令使用 Get-JobTriggerName 参数来获取 BackupJob 计划作业的作业触发器。

示例 2:按 ID 获取作业触发器

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-JobTriggerID 参数来获取计划作业的作业触发器。

示例 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

获取指定的作业触发器。 输入计划作业的一个或多个作业触发器的触发器 ID。 当由 名称IDInputObject 参数指定的计划作业具有多个作业触发器时,请使用此参数。

参数属性

类型:

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

输出

ScheduledJobTrigger