Get-ScheduledJobOption
获取计划作业的作业选项。
语法
Get-ScheduledJobOption
[-InputObject] <ScheduledJobDefinition>
[<CommonParameters>]
Get-ScheduledJobOption
[-Id] <Int32>
[<CommonParameters>]
Get-ScheduledJobOption
[-Name] <String>
[<CommonParameters>]
说明
Get-ScheduledJobOption cmdlet 获取计划作业的作业选项。 你可以使用此命令检查作业选项或通过管道将其传递给其他 cmdlet。
不会单独将作业选项保存到磁盘,因为它们是计划作业的一部分。 若要获取某个计划作业的作业选项,请指定该计划作业。
使用 Get-ScheduledJobOption cmdlet 的参数来标识计划作业。 可以按计划作业的名称或标识号来标识计划作业,也可以通过将 ScheduledJob 对象(例如 Get-ScheduledJob cmdlet 返回的对象)输入或管道连接到 Get-ScheduledJobOption。
Get-ScheduledJobOption 是 PSScheduledJob 模块(包含在 Windows PowerShell 中)中的一系列作业计划 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 属性的值为 $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 变量中的选项对象。
示例 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。
Type: | Int32 |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-InputObject
指定计划作业。 请输入包含 ScheduledJob 对象的变量,或者键入获取 ScheduledJob 对象的命令或表达式,例如 Get-ScheduledJob 命令。 还可以通过管道将 ScheduledJob 对象传递给 Get-ScheduledJobOption。
Type: | ScheduledJobDefinition |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Name
指定计划作业的名称。 Get-ScheduledJobOption 可获取指定的计划作业的作业选项。 支持通配符。
若要获取本地计算机或远程计算机上的计划作业的名称,请使用 Get-ScheduledJob cmdlet。
Type: | String |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
输入
可以通过管道将计划作业从 Get-ScheduledJob 传递到 Get-ScheduledJobOption。
输出
相关链接
- 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