Export (0) Print
Expand All

Resume-Job

Updated: May 8, 2014

Applies To: Windows PowerShell 4.0

Resume-Job

Restarts a suspended job

Aliases

The following abbreviations are aliases for this cmdlet:

  • rujb

Syntax

Parameter Set: SessionIdParameterSet
Resume-Job [-Id] <Int32[]> [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: __AllParameterSets
Resume-Job [-Wait] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: FilterParameterSet
Resume-Job [-Filter] <Hashtable> [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: InstanceIdParameterSet
Resume-Job [-InstanceId] <Guid[]> [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: JobParameterSet
Resume-Job [-Job] <Job[]> [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: NameParameterSet
Resume-Job [-Name] <String[]> [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: StateParameterSet
Resume-Job [-State] <JobState> [-Confirm] [-WhatIf] [ <CommonParameters>]




Detailed Description

The Resume-Job cmdlet resumes a workflow job that was suspended, such as by using the Suspend-Job cmdlet or the about_Suspend-Workflow activity. When a workflow job is resumed, the job engine reconstructs the state, metadata, and output from saved resources, such as checkpoints, so the job is restarted without any loss of state or data. The job state is changed from Suspended to Running.

Use the parameters of Resume-Job to select jobs by name, ID, instance ID or pipe a job object, such as one returned by the Get-Job cmdlet, to Resume-Job. You can also use a property filter to select a job to be resumed.

By default, Resume-Job returns immediately, even though all jobs might not yet be resumed. To suppress the command prompt until all specified jobs are resumed, use the Wait parameter.

The Resume-Job cmdlet works only on custom job types, such as workflow jobs. It does not work on standard background jobs, such as those that are started by using the Start-Job cmdlet. If you submit a job of an unsupported type, Resume-Job generates a terminating error and stops running.

To identify a workflow job, look for a value of PSWorkflowJob in the PSJobTypeName property of the job. To determine whether a particular custom job type supports the Resume-Job cmdlet, see the help topics for the custom job type.

NOTE: Before using a Job cmdlet on a custom job type, import the module that supports the custom job type, either by using the Import-Module cmdlet or getting or using a cmdlet in the module.

This cmdlet is introduced in Windows PowerShell 3.0.

Parameters

-Filter<Hashtable>

Resumes only jobs that satisfy all of the conditions established in the associated hash table. Enter a hash table where the keys are job properties and the values are job property values.


Aliases

none

Required?

true

Position?

1

Default Value

None

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-Id<Int32[]>

Resumes the jobs with the specified IDs.

The ID is an integer that uniquely identifies the job within the current session. It is easier to remember and to type than the instance ID, but it is unique only within the current session. You can type one or more IDs (separated by commas). To find the ID of a job, use the Get-Job cmdlet.


Aliases

none

Required?

true

Position?

1

Default Value

None

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-InstanceId<Guid[]>

Resumes jobs with the specified instance IDs. The default is all jobs.

An instance ID is a GUID that uniquely identifies the job on the computer. To find the instance ID of a job, use the Get-Job cmdlet.


Aliases

none

Required?

true

Position?

1

Default Value

None

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-Job<Job[]>

Specifies the jobs to be resumed. Enter a variable that contains the jobs or a command that gets the jobs. You can also pipe jobs to the Resume-Job cmdlet.


Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

True (ByValue, ByPropertyName)

Accept Wildcard Characters?

false

-Name<String[]>

Resumes jobs with the specified friendly names. Enter one or more job names. Wildcards are supported.


Aliases

none

Required?

true

Position?

1

Default Value

None

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-State<JobState>

Resumes only those jobs in the specified state. Valid values are NotStarted, Running, Completed, Failed, Stopped, Blocked, Suspended, Disconnected, Suspending, and Stopping, but Resume-Job resumes only jobs in the Suspended state.

For more information about job states, see "JobState Enumeration" in MSDN at http://msdn.microsoft.com/en-us/library/windows/desktop/system.management.automation.jobstate(v=vs.85).aspx


Aliases

none

Required?

true

Position?

1

Default Value

None

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-Wait

Suspends the command prompt until all specified jobs are resumed. By default, Resume-Job returns immediately.


Aliases

none

Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Confirm

Prompts you for confirmation before running the cmdlet.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see  about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • System.Management.Automation.Job

    You can pipe all types of jobs to Resume-Job. However, if Resume-Job gets a job of an unsupported type, it throws a terminating error.


Outputs

The output type is the type of the objects that the cmdlet emits.

  • None or System.Management.Automation.Job

    If you use the PassThru parameter, Resume-Job returns the jobs that it tried to resume. Otherwise, this cmdlet does not generate any output.


Notes

  • Resume-Job can only resume jobs that are suspended. If you submit a job in a different state, Resume-Job runs the resume operation on the job, but generates a warning to notify you that the job could not be resumed. To suppress the warning, use the WarningAction common parameter with a value of SilentlyContinue.

  • If a job is not of a type that supports resuming, such as a workflow job (PSWorkflowJob), Resume-Job throws a terminating error.

  • The mechanism and location for saving a suspended job might vary depending on the job type. For example, suspended workflow jobs are saved in a flat file store by default, but can also be saved in a SQL database.

  • When you resume a job, the job state changes from Suspended to Running. To find the jobs that are running, including those that were resumed by this cmdlet, use the State parameter of the Get-Job cmdlet to get jobs in the Running state.

  • Some job types have options or properties that prevent Windows PowerShell from suspending the job. If attempts to suspend the job fail, verify that the job options and properties allow suspending.

Examples

Example 1: Resume a job by ID

The commands in this example verify that the job is a suspended workflow job and then resume the job.


 

The first command uses the Get-Job cmdlet to get the job. The output shows that the job is a suspended workflow job.


PS C:\> Get-Job EventJob
Id     Name            PSJobTypeName   State         HasMoreData     Location   Command
-- ---- ------------- ----- ----------- -------- -------
4 EventJob PSWorkflowJob Suspended True Server01 \\Script\Share\Event.ps1

 

The second command uses the Id parameter of the Resume-Job cmdlet to resume the job with an Id value of 4.


PS C:\> Resume-Job -Id 4

Example 2: Resume a job by name

This command uses the Name parameter to resume several workflow jobs on the local computer.


PS C:\> Resume-Job -Name WorkflowJob, InventoryWorkflow, WFTest*

Example 3: Use custom property values

This command uses the value of a custom property to identify the workflow job to resume. It uses the Filter parameter to identify the workflow job by its CustomID property. It also uses the State parameter to verify that the workflow job is suspended, before it tries to resume it.


PS C:\> Resume-Job -Filter @{CustomID="T091291"} -State Suspended

Example 4: Resume all suspended jobs on a remote computer

This command resumes all suspended jobs on the Srv01 remote computer.

The command uses the Invoke-Command cmdlet to run a command on the Srv01 computer. The remote command uses the State parameter of the Get-Job cmdlet to get all suspended jobs on the computer. A pipeline operator (|) sends the suspended jobs to the Resume-Job cmdlet, which resumes them.


PS C:\> Invoke-Command -ComputerName Srv01 -ScriptBlock {Get-Job -State Suspended | Resume-Job}

Example 4: Wait for jobs to resume

This command uses the Wait parameter to direct Resume-Job to return only after all specified jobs are resumed. The Wait parameter is especially useful in scripts that assume that jobs are resumed before the script continues.


PS C:\> Resume-Job -Name WorkflowJob, InventoryWorkflow, WFTest* -Wait

Example 5: Resume a Workflow that Suspends Itself

The Resume-Job cmdlet lets you resume a workflow job that was suspend by using the Suspend-Workflow activity. This activity suspends a workflow from within a workflow. It is valid only in workflows.

For information about the Suspend-Workflow, see about_Suspend-Workflow.


 

This code sample shows the Suspend-Workflow activity in a workflow.


#SampleWorkflow
Workflow Test-Suspend
{
    $a = Get-Date
    Suspend-Workflow
    (Get-Date)- $a
}

 

The following command runs the Test-Suspend workflow on the Server01 computer.

When you run the workflow, the workflow runs the Get-Date activity and saves the result in the $a variable. Then it runs the Suspend-Workflow activity. In response, it takes a checkpoint, suspends the workflow, and returns a workflow job object. Suspend-Workflow returns a workflow job object even if the workflow is not explicitly run as a job.


PS C:\> Test-Suspend -PSComputerName Server01
Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
-- ---- ------------- ----- ----------- -------- -------
8 Job8 PSWorkflowJob Suspended True Server01 Test-Suspend

 

The following command resumes the Test-Suspend workflow in Job8. It uses the Wait parameter to hold the command prompt until the job is resumed.


PS C:\> Resume-Job -Name Job8 -Wait
Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
-- ---- ------------- ----- ----------- -------- -------
8 Job8 PSWorkflowJob Running True Server01 Test-Suspend

 

This command uses the Receive-Job cmdlet to get the results of the Test-Suspend workflow.

The final command in the workflow returns a TimeSpan object that represents the elapsed time between the current date and time and the date and time that was saved in the $a variable before the workflow was suspended.


PS C:\> Receive-Job -Name Job8
        Days              : 0
Hours : 0
Minutes : 0
Seconds : 19
Milliseconds : 823
Ticks : 198230041
TotalDays : 0.000229432917824074
TotalHours : 0.00550639002777778
TotalMinutes : 0.330383401666667
TotalSeconds : 19.8230041
TotalMilliseconds : 19823.0041
PSComputerName : Server01

Related topics



Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft