en-us/Microsoft.PowerShell.ThreadJob.dll-Help.xml

<?xml version="1.0" encoding="utf-8"?>
<helpItems schema="maml" xmlns="http://msh">
  <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
    <command:details>
      <command:name>Start-ThreadJob</command:name>
      <command:verb>Start</command:verb>
      <command:noun>ThreadJob</command:noun>
      <maml:description>
        <maml:para>Starts a PowerShell job in a separate thread</maml:para>
      </maml:description>
    </command:details>
    <maml:description>
      <maml:para>This command starts a PowerShell job running in a separate thread. It is similar to the 'Start-Job' command, except that it runs the job in a different thread instead of a child process. Consequently, it uses fewer resources for each job.</maml:para>
    </maml:description>
    <command:syntax>
      <command:syntaxItem>
        <maml:name>Start-ThreadJob</maml:name>
        <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="0" aliases="none">
          <maml:name>FilePath</maml:name>
          <maml:description>
            <maml:para>Specifies an optional filepath to script for the job to run.</maml:para>
          </maml:description>
          <command:parameterValue required="true" variableLength="false">String</command:parameterValue>
          <dev:type>
            <maml:name>String</maml:name>
            <maml:uri />
          </dev:type>
          <dev:defaultValue>None</dev:defaultValue>
        </command:parameter>
        <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
          <maml:name>ArgumentList</maml:name>
          <maml:description>
            <maml:para>Provides an optional list of arguments to be used in the job script.</maml:para>
          </maml:description>
          <command:parameterValue required="true" variableLength="false">Object[]</command:parameterValue>
          <dev:type>
            <maml:name>Object[]</maml:name>
            <maml:uri />
          </dev:type>
          <dev:defaultValue>None</dev:defaultValue>
        </command:parameter>
        <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
          <maml:name>InitializationScript</maml:name>
          <maml:description>
            <maml:para>Optional script block for script to be run before the job script or file is run.</maml:para>
          </maml:description>
          <command:parameterValue required="true" variableLength="false">ScriptBlock</command:parameterValue>
          <dev:type>
            <maml:name>ScriptBlock</maml:name>
            <maml:uri />
          </dev:type>
          <dev:defaultValue>None</dev:defaultValue>
        </command:parameter>
        <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByValue)" position="named" aliases="none">
          <maml:name>InputObject</maml:name>
          <maml:description>
            <maml:para>Optional pipeline input to be processed in the running job.</maml:para>
          </maml:description>
          <command:parameterValue required="true" variableLength="false">PSObject</command:parameterValue>
          <dev:type>
            <maml:name>PSObject</maml:name>
            <maml:uri />
          </dev:type>
          <dev:defaultValue>None</dev:defaultValue>
        </command:parameter>
        <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
          <maml:name>Name</maml:name>
          <maml:description>
            <maml:para>Optional of the job created to run the script.</maml:para>
          </maml:description>
          <command:parameterValue required="true" variableLength="false">String</command:parameterValue>
          <dev:type>
            <maml:name>String</maml:name>
            <maml:uri />
          </dev:type>
          <dev:defaultValue>None</dev:defaultValue>
        </command:parameter>
        <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
          <maml:name>StreamingHost</maml:name>
          <maml:description>
            <maml:para>Optional host object to which job output can directed.</maml:para>
          </maml:description>
          <command:parameterValue required="true" variableLength="false">PSHost</command:parameterValue>
          <dev:type>
            <maml:name>PSHost</maml:name>
            <maml:uri />
          </dev:type>
          <dev:defaultValue>None</dev:defaultValue>
        </command:parameter>
        <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
          <maml:name>ThrottleLimit</maml:name>
          <maml:description>
            <maml:para>Optional value that determines the maximum number of thread jobs that can run at one time. If jobs are created that exceed this value, then those jobs are save in a queue until one or more running jobs complete, after which a new job will be started running.</maml:para>
          </maml:description>
          <command:parameterValue required="true" variableLength="false">Int32</command:parameterValue>
          <dev:type>
            <maml:name>Int32</maml:name>
            <maml:uri />
          </dev:type>
          <dev:defaultValue>5</dev:defaultValue>
        </command:parameter>
      </command:syntaxItem>
      <command:syntaxItem>
        <maml:name>Start-ThreadJob</maml:name>
        <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="0" aliases="none">
          <maml:name>ScriptBlock</maml:name>
          <maml:description>
            <maml:para>Script block that is run in the thread job.</maml:para>
          </maml:description>
          <command:parameterValue required="true" variableLength="false">ScriptBlock</command:parameterValue>
          <dev:type>
            <maml:name>ScriptBlock</maml:name>
            <maml:uri />
          </dev:type>
          <dev:defaultValue>None</dev:defaultValue>
        </command:parameter>
        <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
          <maml:name>ArgumentList</maml:name>
          <maml:description>
            <maml:para>Provides an optional list of arguments to be used in the job script.</maml:para>
          </maml:description>
          <command:parameterValue required="true" variableLength="false">Object[]</command:parameterValue>
          <dev:type>
            <maml:name>Object[]</maml:name>
            <maml:uri />
          </dev:type>
          <dev:defaultValue>None</dev:defaultValue>
        </command:parameter>
        <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
          <maml:name>InitializationScript</maml:name>
          <maml:description>
            <maml:para>Optional script block for script to be run before the job script or file is run.</maml:para>
          </maml:description>
          <command:parameterValue required="true" variableLength="false">ScriptBlock</command:parameterValue>
          <dev:type>
            <maml:name>ScriptBlock</maml:name>
            <maml:uri />
          </dev:type>
          <dev:defaultValue>None</dev:defaultValue>
        </command:parameter>
        <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByValue)" position="named" aliases="none">
          <maml:name>InputObject</maml:name>
          <maml:description>
            <maml:para>Optional pipeline input to be processed in the running job.</maml:para>
          </maml:description>
          <command:parameterValue required="true" variableLength="false">PSObject</command:parameterValue>
          <dev:type>
            <maml:name>PSObject</maml:name>
            <maml:uri />
          </dev:type>
          <dev:defaultValue>None</dev:defaultValue>
        </command:parameter>
        <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
          <maml:name>Name</maml:name>
          <maml:description>
            <maml:para>Optional of the job created to run the script.</maml:para>
          </maml:description>
          <command:parameterValue required="true" variableLength="false">String</command:parameterValue>
          <dev:type>
            <maml:name>String</maml:name>
            <maml:uri />
          </dev:type>
          <dev:defaultValue>None</dev:defaultValue>
        </command:parameter>
        <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
          <maml:name>StreamingHost</maml:name>
          <maml:description>
            <maml:para>Optional host object to which job output can directed.</maml:para>
          </maml:description>
          <command:parameterValue required="true" variableLength="false">PSHost</command:parameterValue>
          <dev:type>
            <maml:name>PSHost</maml:name>
            <maml:uri />
          </dev:type>
          <dev:defaultValue>None</dev:defaultValue>
        </command:parameter>
        <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
          <maml:name>ThrottleLimit</maml:name>
          <maml:description>
            <maml:para>Optional value that determines the maximum number of thread jobs that can run at one time. If jobs are created that exceed this value, then those jobs are save in a queue until one or more running jobs complete, after which a new job will be started running.</maml:para>
          </maml:description>
          <command:parameterValue required="true" variableLength="false">Int32</command:parameterValue>
          <dev:type>
            <maml:name>Int32</maml:name>
            <maml:uri />
          </dev:type>
          <dev:defaultValue>5</dev:defaultValue>
        </command:parameter>
      </command:syntaxItem>
    </command:syntax>
    <command:parameters>
      <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
        <maml:name>ArgumentList</maml:name>
        <maml:description>
          <maml:para>Provides an optional list of arguments to be used in the job script.</maml:para>
        </maml:description>
        <command:parameterValue required="true" variableLength="false">Object[]</command:parameterValue>
        <dev:type>
          <maml:name>Object[]</maml:name>
          <maml:uri />
        </dev:type>
        <dev:defaultValue>None</dev:defaultValue>
      </command:parameter>
      <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="0" aliases="none">
        <maml:name>FilePath</maml:name>
        <maml:description>
          <maml:para>Specifies an optional filepath to script for the job to run.</maml:para>
        </maml:description>
        <command:parameterValue required="true" variableLength="false">String</command:parameterValue>
        <dev:type>
          <maml:name>String</maml:name>
          <maml:uri />
        </dev:type>
        <dev:defaultValue>None</dev:defaultValue>
      </command:parameter>
      <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
        <maml:name>InitializationScript</maml:name>
        <maml:description>
          <maml:para>Optional script block for script to be run before the job script or file is run.</maml:para>
        </maml:description>
        <command:parameterValue required="true" variableLength="false">ScriptBlock</command:parameterValue>
        <dev:type>
          <maml:name>ScriptBlock</maml:name>
          <maml:uri />
        </dev:type>
        <dev:defaultValue>None</dev:defaultValue>
      </command:parameter>
      <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByValue)" position="named" aliases="none">
        <maml:name>InputObject</maml:name>
        <maml:description>
          <maml:para>Optional pipeline input to be processed in the running job.</maml:para>
        </maml:description>
        <command:parameterValue required="true" variableLength="false">PSObject</command:parameterValue>
        <dev:type>
          <maml:name>PSObject</maml:name>
          <maml:uri />
        </dev:type>
        <dev:defaultValue>None</dev:defaultValue>
      </command:parameter>
      <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
        <maml:name>Name</maml:name>
        <maml:description>
          <maml:para>Optional of the job created to run the script.</maml:para>
        </maml:description>
        <command:parameterValue required="true" variableLength="false">String</command:parameterValue>
        <dev:type>
          <maml:name>String</maml:name>
          <maml:uri />
        </dev:type>
        <dev:defaultValue>None</dev:defaultValue>
      </command:parameter>
      <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="0" aliases="none">
        <maml:name>ScriptBlock</maml:name>
        <maml:description>
          <maml:para>Script block that is run in the thread job.</maml:para>
        </maml:description>
        <command:parameterValue required="true" variableLength="false">ScriptBlock</command:parameterValue>
        <dev:type>
          <maml:name>ScriptBlock</maml:name>
          <maml:uri />
        </dev:type>
        <dev:defaultValue>None</dev:defaultValue>
      </command:parameter>
      <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
        <maml:name>StreamingHost</maml:name>
        <maml:description>
          <maml:para>Optional host object to which job output can directed.</maml:para>
        </maml:description>
        <command:parameterValue required="true" variableLength="false">PSHost</command:parameterValue>
        <dev:type>
          <maml:name>PSHost</maml:name>
          <maml:uri />
        </dev:type>
        <dev:defaultValue>None</dev:defaultValue>
      </command:parameter>
      <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
        <maml:name>ThrottleLimit</maml:name>
        <maml:description>
          <maml:para>Optional value that determines the maximum number of thread jobs that can run at one time. If jobs are created that exceed this value, then those jobs are save in a queue until one or more running jobs complete, after which a new job will be started running.</maml:para>
        </maml:description>
        <command:parameterValue required="true" variableLength="false">Int32</command:parameterValue>
        <dev:type>
          <maml:name>Int32</maml:name>
          <maml:uri />
        </dev:type>
        <dev:defaultValue>5</dev:defaultValue>
      </command:parameter>
    </command:parameters>
    <command:inputTypes>
      <command:inputType>
        <dev:type>
          <maml:name>System.Management.Automation.PSObject</maml:name>
        </dev:type>
        <maml:description>
          <maml:para></maml:para>
        </maml:description>
      </command:inputType>
    </command:inputTypes>
    <command:returnValues>
      <command:returnValue>
        <dev:type>
          <maml:name>Microsoft.PowerShell.ThreadJob.ThreadJob</maml:name>
        </dev:type>
        <maml:description>
          <maml:para></maml:para>
        </maml:description>
      </command:returnValue>
    </command:returnValues>
    <maml:alertSet>
      <maml:alert>
        <maml:para></maml:para>
      </maml:alert>
    </maml:alertSet>
    <command:examples>
      <command:example>
        <maml:title>-------------------------- Example 1 --------------------------</maml:title>
        <dev:code>PS C:\&gt; $job = Start-ThreadJob -ScriptBlock { 1..5 | foreach { "Output: $_"; sleep 1 }}
PS C:\&gt; $job
 
Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
1 Job1 ThreadJob Running False PowerShell 1..5 | foreach {
 
$job | Wait-Job | Receive-Job
Output: 1
Output: 2
Output: 3
Output: 4
Output: 5
 
PS C:\&gt; $job
 
Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
1 Job1 ThreadJob Completed False PowerShell 1..5 | foreach {</dev:code>
        <dev:remarks>
          <maml:para>This example starts a simple job script running in a separate thread. It then uses the 'Wait-Job' and 'Receive-Job' commands to wait for the job to complete and then return output.</maml:para>
        </dev:remarks>
      </command:example>
      <command:example>
        <maml:title>-------------------------- Example 2 --------------------------</maml:title>
        <dev:code>PS C:\&gt; $jobs = 1..5 | foreach { Start-ThreadJob -ScriptBlock { 1..10 | foreach { sleep 1; "Job Done" } } -ThrottleLimit 3 }
PS C:\&gt; $jobs
 
Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
1 Job19 ThreadJob Running True PowerShell 1..10 | foreach { sleep…
2 Job20 ThreadJob Running True PowerShell 1..10 | foreach { sleep…
3 Job21 ThreadJob Running True PowerShell 1..10 | foreach { sleep…
4 Job22 ThreadJob NotStarted False PowerShell 1..10 | foreach { sleep…
5 Job23 ThreadJob NotStarted False PowerShell 1..10 | foreach { sleep…</dev:code>
        <dev:remarks>
          <maml:para>This example runs 'Start-ThreadJob' five times to start five job instances, but with a throttle limit value of 3. Consequently, only three of the five jobs are initially running and the other two are not started but queued to run after one or more of the currently running jobs complete.</maml:para>
        </dev:remarks>
      </command:example>
    </command:examples>
    <command:relatedLinks />
  </command:command>
</helpItems>