Disable-ScheduledJob
禁用计划作业。
语法
Definition (默认值)
Disable-ScheduledJob
[-InputObject] <ScheduledJobDefinition>
[-PassThru]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
DefinitionId
Disable-ScheduledJob
[-Id] <Int32>
[-PassThru]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
DefinitionName
Disable-ScheduledJob
[-Name] <String>
[-PassThru]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
说明
Disable-ScheduledJob cmdlet 暂时禁用计划作业。 禁用会保留所有作业属性,并且不会禁用作业触发器,但会阻止计划作业在触发时自动启动。 可以使用 Start-Job cmdlet 启动禁用的计划作业,也可以使用禁用的计划作业作为模板。
若要禁用计划作业,Disable-ScheduledJob cmdlet 会将计划作业的 Enabled 属性设置为 False($false)。 若要重新启用计划作业,请使用 Enable-ScheduledJob cmdlet。
Disable-ScheduledJob 是 Windows PowerShell 中包含的 PSScheduledJob 模块中的作业计划 cmdlet 集合之一。
有关计划作业的详细信息,请参阅 PSScheduledJob 模块中的“关于”主题。
导入 PSScheduledJob 模块,然后键入:Get-Help about_Scheduled* 或查看about_Scheduled_Jobs。
此 cmdlet 已在 Windows PowerShell 3.0 中引入。
示例
示例 1:禁用计划作业
PS C:\> Disable-ScheduledJob -ID 2 -Passthru
Id Name Triggers Command Enabled
-- ---- -------- ------- -------
2 Inventory {1, 2} \\Srv01\Scripts\Get-FullInventory.ps1 False
此命令禁用本地计算机上 ID 为 2 的计划作业。 输出显示命令的效果。
示例 2:禁用所有计划作业
PS C:\> Get-ScheduledJob | Disable-ScheduledJob -Passthru
Id Name Triggers Command Enabled
-- ---- -------- ------- -------
1 ArchiveProje... {} C:\Scripts\Archive-DxProjects.ps1 False
2 Inventory {1, 2} \\Srv01\Scripts\Get-FullInventory.ps1 False
4 Test-HelpFiles {1} .\Test-HelpFiles.ps1 False
5 TestJob {1, 2} .\Run-AllTests.ps1 False
此命令禁用本地计算机上的所有计划作业。 它使用 Get-ScheduledJob cmdlet 获取所有计划作业和 Disable-ScheduledJob cmdlet 来禁用它们。
可以使用 Enable-ScheduledJob cmdlet 重新启用计划作业,并使用 Start-Job cmdlet 运行禁用的计划作业。
Disable-ScheduledJob 如果禁用已禁用的计划作业,则不会生成警告或错误,因此可以在没有条件的情况下禁用所有计划作业。
示例 3:禁用选定的计划作业
PS C:\> Get-ScheduledJob | Where-Object {!$_.Credential} | Disable-ScheduledJob
此命令禁用计划的作业不包括凭据。 没有凭据的作业使用创建凭据的用户的权限运行。
该命令使用 Get-ScheduledJob cmdlet 获取计算机上的所有计划作业。 管道运算符将计划作业发送到 Where-Object cmdlet,该 cmdlet 选择没有凭据的计划作业。 该命令使用 not (!) 运算符并引用计划作业的 Credential 属性。 另一个管道运算符将选定的计划作业发送到禁用它们的 Disable-ScheduledJob cmdlet。
示例 4:禁用远程计算机上的计划作业
PS C:\> Invoke-Command -ComputerName Srv01, Srv10 -ScriptBlock {Disable-ScheduledJob -Name TestJob}
此命令在两台远程计算机上禁用 TestJob 计划作业,即 Srv01 和 Srv10。
该命令使用 Invoke-Command cmdlet 在 Srv01 和 Srv10 计算机上运行 Disable-ScheduledJob 命令。 该命令使用 Disable-ScheduledJob 的 Name 参数来选择每台计算机上的 TestJob 计划作业。
示例 5:按计划作业的全局 ID 禁用计划作业
The first command demonstrates one way of finding the GlobalID of a scheduled job. The command uses the Get-ScheduledJob cmdlet to get the scheduled jobs on the computer. A pipeline operator (|) sends the scheduled jobs to the Format-Table cmdlet, which displays the Name, GlobalID, and Command properties of each job in a table.
PS C:\> Get-ScheduledJob | Format-Table -Property Name, GlobalID, Command -Autosize
Name GlobalId Command
---- -------- -------
ArchiveProjects1 a26a0b3d-b4e6-44d3-8b95-8706ef621f7c C:\Scripts\Archive-DxProjects.ps1
Inventory 3ac37e5d-84c0-4a8f-9661-7e88ebb8f914 \\Srv01\Scripts\Get-FullInventory.ps1
Backup-Scripts 4d0cc6be-c082-48d1-baec-1bd8278f3c81 Copy-Item C:\CurrentScripts\*.ps1 -Destination C:\BackupScripts
Test-HelpFiles d77020ca-f20d-42be-86c8-fc64df97db90 .\Test-HelpFiles.ps1
Test-HelpFiles 2f1606d2-c6cf-4bef-8b1c-ae36a9cc9934 .\Test-DomainHelpFiles.ps1
The second command uses the Get-ScheduledJob cmdlet to get the scheduled jobs on the computer. A pipeline operator (|) sends the scheduled jobs to the Where-Object cmdlet, which selects the scheduled job with the specified global ID. Another pipeline operator sends the job to the **Disable-ScheduledJob** cmdlet, which disables it.
PS C:\> Get-ScheduledJob | Where-Object {$_.GlobalID = d77020ca-f20d-42be-86c8-fc64df97db90} | Disable-ScheduledJob
此示例演示如何使用计划作业的全局标识符来禁用计划作业。 计划作业的 GlobalID 属性的值是唯一标识符(GUID)。 需要精度时使用 GlobalID 值,例如,在多台计算机上禁用计划作业时。
参数
-Confirm
在运行 cmdlet 之前,提示你进行确认。
参数属性
| 类型: | SwitchParameter |
| 默认值: | False |
| 支持通配符: | False |
| 不显示: | False |
| 别名: | cf |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-Id
禁用具有指定标识号(ID)的计划作业。 输入计划作业的 ID。
参数属性
| 类型: | Int32 |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
DefinitionId
| Position: | 0 |
| 必需: | True |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-InputObject
指定要禁用的计划作业。 输入包含 ScheduledJobDefinition 的变量 对象或键入 ScheduledJobDefinition 对象(如 Get-ScheduledJob 命令)的命令或表达式。 还可以通过管道将 ScheduledJobDefinition 对象传递给 Disable-ScheduledJob。
参数属性
| 类型: | ScheduledJobDefinition |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
Definition
| Position: | 0 |
| 必需: | True |
| 来自管道的值: | True |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-Name
禁用具有指定名称的计划作业。 输入计划作业的名称。 支持通配符。
参数属性
| 类型: | String |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
DefinitionName
| Position: | 0 |
| 必需: | True |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-PassThru
返回一个对象,该对象表示你正在处理的项目。 默认情况下,此 cmdlet 不生成任何输出。
参数属性
| 类型: | SwitchParameter |
| 默认值: | False |
| 支持通配符: | False |
| 不显示: | False |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-WhatIf
显示 cmdlet 运行时会发生什么情况。 命令脚本未运行。
参数属性
| 类型: | SwitchParameter |
| 默认值: | False |
| 支持通配符: | False |
| 不显示: | False |
| 别名: | 无线 |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
CommonParameters
此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters。
输入
ScheduledJobDefinition
可以通过管道将计划作业传递给 Disable-ScheduledJob。
输出
None or Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition
如果使用 Passthru 参数,Disable-ScheduledJob 返回已禁用的计划作业。 否则,此 cmdlet 不会生成任何输出。
备注
- Disable-ScheduledJob 如果不使用它禁用已禁用的计划作业,则不会生成警告或错误。
相关链接
- 关于计划任务
- 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