Get-ScheduledJobOption
获取计划作业的作业选项。
语法
JobDefinition (默认值)
Get-ScheduledJobOption
[-InputObject] <ScheduledJobDefinition>
[<CommonParameters>]
JobDefinitionId
Get-ScheduledJobOption
[-Id] <Int32>
[<CommonParameters>]
JobDefinitionName
Get-ScheduledJobOption
[-Name] <String>
[<CommonParameters>]
说明
Get-ScheduledJobOption cmdlet 获取计划作业的作业选项。 可以使用此命令检查作业选项,或通过管道将作业选项传递给其他 cmdlet。
作业选项不会单独保存到磁盘;它们是计划作业的一部分。 若要获取计划作业的作业选项,请指定计划作业。
使用 Get-ScheduledJobOption cmdlet 的参数来标识计划作业。 可以通过计划作业的名称或标识号,或通过输入或管道 ScheduledJob 对象(例如由 Get-ScheduledJob cmdlet 返回的作业)来 Get-ScheduledJobOption。
Get-ScheduledJobOption 是 WINDOWS PowerShell 中包含的 PSScheduledJob 模块中作业计划 cmdlet 的集合之一。
有关计划作业的详细信息,请参阅 PSScheduledJob 模块中的“关于”主题。
导入 PSScheduledJob 模块,然后键入:Get-Help about_Scheduled* 或查看about_Scheduled_Jobs。
此 cmdlet 已在 Windows PowerShell 3.0 中引入。
示例
示例 1:获取作业选项
PS C:\> Get-ScheduledJobOption -Name "*Backup*"
StartIfOnBatteries : False
StopIfGoingOnBatteries : True
WakeToRun : False
StartIfNotIdle : True
StopIfGoingOffIdle : False
RestartOnIdleResume : False
IdleDuration : 00:10:00
IdleTimeout : 01:00:00
ShowInTaskScheduler : True
RunElevated : True
RunWithoutNetwork : True
DoNotAllowDemandStart : False
MultipleInstancePolicy : Ignore
NewJobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition
此命令获取其名称中包含 BackUp 的计划作业的作业选项。 结果显示返回的 Get-ScheduledJobOption 的作业选项对象。
示例 2:获取所有作业选项
PS C:\> Get-ScheduledJob | Get-ScheduledJobOptions
此命令获取本地计算机上所有计划作业的作业选项。
它使用 Get-ScheduledJob cmdlet 在本地计算机上获取计划作业。 管道运算符 (|) 将计划作业发送到 Get-ScheduledJobOptions cmdlet,该 cmdlet 获取每个计划作业的作业选项。
示例 3:获取所选作业选项
PS C:\> Get-ScheduledJob | Get-ScheduledJobOption | Where {$_.RunElevated -and !$_.WaketoRun}
StartIfOnBatteries : False
StopIfGoingOnBatteries : True
WakeToRun : True
StartIfNotIdle : True
StopIfGoingOffIdle : False
RestartOnIdleResume : False
IdleDuration : 00:10:00
IdleTimeout : 01:00:00
ShowInTaskScheduler : True
RunElevated : True
RunWithoutNetwork : True
DoNotAllowDemandStart : False
MultipleInstancePolicy : Ignore
NewJobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition
The second command shows how to find to which scheduled job the job options belong. This command uses a pipeline operator (|) to send the selected job options to the ForEach-Object cmdlet, which gets the JobDefinition property of each options object. The JobDefinition property contains the originating job object. The results show that the selected options came from the DeployPkg scheduled job.
PS C:\> Get-ScheduledJob | Get-ScheduledJobOption | Where {$_.RunElevated -and !$_.WaketoRun} | ForEach-Object {$_.JobDefinition}
Id Name Triggers Command Enabled
-- ---- -------- ------- -------
2 DeployPkg {1, 2} DeployPackage.ps1 True
此示例演示如何查找具有特定值的作业选项对象。
第一个命令获取 RunElevated 属性的作业选项,其中 RunElevated 属性的值为 $True,RunWithoutNetwork 属性的值为 $False。 输出显示所选 JobOptions 对象。
示例 4:使用作业选项创建新作业
PS C:\> $Opts = Get-ScheduledJobOption -Name "BackupTestLogs"
PS C:\> Register-ScheduledJob -Name "Archive-Scripts" -FilePath "\\Srv01\Scripts\ArchiveScripts.ps1" -ScheduledJobOption $Opts
此示例演示如何使用 Get-ScheduledJobOptions 在新计划作业中获取的作业选项。
第一个命令使用 Get-ScheduledJobOptions 来获取 BackupTestLogs 计划作业的作业选项。 该命令将选项保存在$Opts变量中。
第二个命令使用 Register-ScheduledJob cmdlet 创建新的计划作业。 ScheduledJobOption 参数的值是$Opts变量中的 options 对象。
示例 5:从远程计算机获取作业选项
PS C:\> $O = Invoke-Command -ComputerName "Srv01" -ScriptBlock {Get-ScheduledJob -Name "DataDemon" }
此命令使用 Invoke-Command cmdlet 获取 Srv01 计算机上的 DataDemon 作业的计划作业选项。 该命令将选项保存在$O变量中。
参数
-Id
指定计划作业的标识号。 Get-ScheduledJobOption 获取指定计划作业的作业选项。
若要获取本地计算机或远程计算机上的计划作业的标识号,请使用 Get-ScheduledJob cmdlet。
参数属性
| 类型: | Int32 |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
JobDefinitionId
| Position: | 0 |
| 必需: | True |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-InputObject
指定计划作业。 输入一个变量,其中包含 ScheduledJob 对象,或键入获取 ScheduledJob 对象的命令或表达式,例如 Get-ScheduledJob 命令。 还可以通过管道将 ScheduledJob 对象传递给 Get-ScheduledJobOption。
参数属性
| 类型: | ScheduledJobDefinition |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
JobDefinition
| Position: | 0 |
| 必需: | True |
| 来自管道的值: | True |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-Name
指定计划作业的名称。 Get-ScheduledJobOption 获取指定计划作业的作业选项。 支持通配符。
若要获取本地计算机或远程计算机上的计划作业的名称,请使用 Get-ScheduledJob cmdlet。
参数属性
| 类型: | String |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
JobDefinitionName
| Position: | 0 |
| 必需: | True |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
CommonParameters
此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters。
输入
ScheduledJobDefinition
可以通过管道将计划作业从 Get-ScheduledJob 传递给 Get-ScheduledJobOption。
输出
ScheduledJobOptions
相关链接
- 关于计划任务
- 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