PowerShell Logo Small

Set-ScheduledJob



This is the built-in help made by Microsoft for the command 'Set-ScheduledJob', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Changes scheduled jobs

SYNTAX


Set-ScheduledJob [-InputObject] <ScheduledJobDefinition> [-ArgumentList <Object[]>] [-Authentication <AuthenticationMechanism>] [-Credential <PSCredential>]
[-InitializationScript <ScriptBlock>] [-MaxResultCount <Int32>] [-Name <String>] [-PassThru] [-RunAs32] [-RunNow] [-ScheduledJobOption <ScheduledJobOptions>] [-ScriptBlock
<ScriptBlock>] [-Trigger <ScheduledJobTrigger[]>] [<CommonParameters>]
Set-ScheduledJob [-InputObject] <ScheduledJobDefinition> [-ArgumentList <Object[]>] [-Authentication <AuthenticationMechanism>] [-Credential <PSCredential>] [-FilePath
<String>] [-InitializationScript <ScriptBlock>] [-MaxResultCount <Int32>] [-Name <String>] [-PassThru] [-RunAs32] [-RunNow] [-ScheduledJobOption <ScheduledJobOptions>]
[-Trigger <ScheduledJobTrigger[]>] [<CommonParameters>]
Set-ScheduledJob [-InputObject] <ScheduledJobDefinition> [-ClearExecutionHistory] [-PassThru] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Set-ScheduledJob cmdlet changes the properties of scheduled jobs, such as the commands that the jobs run or the credentials required to run the job. You can also use it
to clear the execution history of the scheduled job.


To use this cmdlet, begin by using the Get-ScheduledJob cmdlet to get the scheduled job. Then, pipe the scheduled job to Set-ScheduledJob or save the job in a variable and
use the InputObject parameter of Set-ScheduledJob to identify the job. Use the remaining parameters of Set-ScheduledJob to change the job properties or clear the execution
history.


Although you can use Set-ScheduledJob to change the triggers and options of a scheduled job, the Add-JobTrigger, Set-JobTrigger, and Set-ScheduledJobOption cmdlets provide
much easier ways to accomplish those tasks. To create a new scheduled job, use the Register-ScheduledJob cmdlet.


The Trigger parameter of Set-ScheduledJob adds one or more job triggers that start the job. The Trigger parameter is optional, so you can add triggers when you create the
scheduled job, add job triggers later, add the RunNow parameter to start the job immediately, use the Start-Job cmdlet to start the job immediately at any time, or save the
untriggered scheduled job as a template for other jobs.


Set-ScheduledJob is one of a collection of job scheduling cmdlets in the PSScheduledJob module that is included in Windows PowerShell.


For more information about Scheduled Jobs, see the About topics in the PSScheduledJob module. Import the PSScheduledJob module and then type: Get-Help about_Scheduled* or
see about_Scheduled_Jobs.


This cmdlet is introduced in Windows PowerShell 3.0.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=290633
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

REMARKS

<

Examples


Example 1: Change the script that a job runs

The first command uses the Get-ScheduledJob cmdlet to get the Inventory scheduled job. The output shows that the job runs the Get-Inventory.ps1 script.This command is not
required; it is included only to show the effect of the script change.
PS C:\>Get-ScheduledJob -Name Inventory
Id Name Triggers Command Enabled
-- ---- -------- ------- -------
1 Inventory {1} C:\Scripts\Get-Inventory.ps1 True

The second command uses the Get-ScheduledJob cmdlet to get the Inventory scheduled job. A pipeline operator (|) sends the scheduled job to the Set-ScheduledJob cmdlet. The
Set-ScheduledJob command uses the Script parameter to specify a new script, Get-FullInventory.ps1. The command uses the Passthru parameter to return the scheduled job after
the change.
PS C:\>Get-ScheduledJob -Name Inventory | Set-ScheduledJob -FilePath C:\Scripts\Get-FullInventory.ps1 -Passthru
Id Name Triggers Command Enabled
-- ---- -------- ------- -------
1 Inventory {1} C:\Scripts\Get-FullInventory.ps1 True



This example shows how to change the script that is run in a scheduled job.




Example 2: Delete the execution history of a scheduled job

PS C:\>Get-ScheduledJob BackupArchive | Set-ScheduledJob -ClearExecutionHistory



This command deletes the current execution history and saved job results for the BackupArchive scheduled job.

The command uses the Get-ScheduledJob cmdlet to get the BackupArchive scheduled job. A pipeline operator (|) sends the job to the Set-ScheduledJob cmdlet to change it. The
Set-ScheduledJob command uses the ClearExecutionHistory parameter to delete the execution history and saved results.

For more information about the execution history and saved job results of scheduled jobs, see about_Scheduled_Jobs.




Example 3: Change scheduled jobs on a remote computer

PS C:\>Invoke-Command -Computer Server01, Server02 -ScriptBlock {Get-ScheduledJob | Set-ScheduledJob -InitializationScript \\SrvA\Scripts\SetForRun.ps1}



This command changes the initialization script in all scheduled jobs on the Server01 and Server02 computers.

The command uses the Invoke-Command cmdlet to run a command on the Server01 and Server02 computers.

The remote command begins with a Get-ScheduledJob command that gets all scheduled jobs on the computer. The scheduled jobs are piped to the Set-ScheduledJob cmdlet which
changes the initialization script to SetForRun.ps1.