New-​Azure​Batch​Task

Creates a Batch task under a job.

Syntax

New-AzureBatchTask
   [-AffinityInformation <PSAffinityInformation>]
   [-ApplicationPackageReferences <PSApplicationPackageReference[]>]
   -BatchContext <BatchAccountContext>
   [-CommandLine <String>]
   [-Constraints <PSTaskConstraints>]
   [-DependsOn <TaskDependencies>]
   [-DisplayName <String>]
   [-EnvironmentSettings <IDictionary>]
   [-ExitConditions <PSExitConditions>]
   -Id <String>
   -JobId <String>
   [-MultiInstanceSettings <PSMultiInstanceSettings>]
   [-ResourceFiles <IDictionary>]
   [-RunElevated]
   [<CommonParameters>]
New-AzureBatchTask
   [-AffinityInformation <PSAffinityInformation>]
   [-ApplicationPackageReferences <PSApplicationPackageReference[]>]
   -BatchContext <BatchAccountContext>
   [-CommandLine <String>]
   [-Constraints <PSTaskConstraints>]
   [-DependsOn <TaskDependencies>]
   [-DisplayName <String>]
   [-EnvironmentSettings <IDictionary>]
   [-ExitConditions <PSExitConditions>]
   -Id <String>
   [-Job <PSCloudJob>]
   [-MultiInstanceSettings <PSMultiInstanceSettings>]
   [-ResourceFiles <IDictionary>]
   [-RunElevated]
   [<CommonParameters>]
New-AzureBatchTask
   -BatchContext <BatchAccountContext>
   [-Job <PSCloudJob>]
   [-Tasks <PSCloudTask[]>]
   [<CommonParameters>]
New-AzureBatchTask
   -BatchContext <BatchAccountContext>
   -JobId <String>
   [-Tasks <PSCloudTask[]>]
   [<CommonParameters>]

Description

The New-AzureBatchTask cmdlet creates an Azure Batch task under the job specified by the JobId parameter or the Job parameter.

Examples

Example 1: Create a Batch task

PS C:\>New-AzureBatchTask -JobId "Job-000001" -Id "Task23" -CommandLine "cmd /c dir /s" -BatchContext $Context

This command creates a task that has the ID Task23 under the job that has the ID Job-000001. The task runs the specified command. Use the Get-AzureRmBatchAccountKeys cmdlet to assign a context to the $Context variable.

Example 2: Create a Batch task

PS C:\>Get-AzureBatchJob -Id "Job-000001" -BatchContext $Context | New-AzureBatchTask -Id "Task26" -CommandLine "cmd /c echo hello > newFile.txt" -RunElevated -BatchContext $Context

This command gets the Batch job that has the ID Job-000001 by using the Get-AzureBatchJob cmdlet. The command passes that job to the current cmdlet by using the pipeline operator. The command creates a task that has the ID Task26 under that job. The task runs the specified command by using elevated permissions.

Example 3: Add a collection of tasks to the specified job by using the pipeline

PS C:\>$Context = Get-AzureRmBatchAccountKeys -AccountName "ContosoBatchAccount"
PS C:\> $Task01 = New-Object Microsoft.Azure.Commands.Batch.Models.PSCloudTask("Task23", "cmd /c dir /s")
PS C:\> $Task02 = New-Object Microsoft.Azure.Commands.Batch.Models.PSCloudTask("Task24", "cmd /c dir /s")
PS C:\> Get-AzureBatchJob -Id "Job-000001" -BatchContext $Context | New-AzureBatchTask -Tasks @($Task01, $Task02) -BatchContext $Context

The first command creates an object reference to the account keys for the batch account named ContosoBatchAccount by using Get-AzureRmBatchAccountKeys. The command stores this object reference in the $Context variable.

The next two commands create PSCloudTask objects by using the New-Object cmdlet. The commands store the tasks in the $Task01 and $Task02 variables.

The final command gets the Batch job that has the ID Job-000001 by using Get-AzureBatchJob. Then the command passes that job to the current cmdlet by using the pipeline operator. The command adds a collection of tasks under that job. The command uses the context stored in $Context.

Example 4: Add a collection of tasks to the specified job

PS C:\>$Context = Get-AzureRmBatchAccountKeys -AccountName "ContosoBatchAccount"
PS C:\> $Task01 = New-Object Microsoft.Azure.Commands.Batch.Models.PSCloudTask("Task23", "cmd /c dir /s")
PS C:\> $Task02 = New-Object Microsoft.Azure.Commands.Batch.Models.PSCloudTask("Task24", "cmd /c dir /s")
PS C:\> New-AzureBatchTask -JobId "Job-000001" -Tasks @($Task01, $Task02) -BatchContext $Context

The first command creates an object reference to the account keys for the batch account named ContosoBatchAccount by using Get-AzureRmBatchAccountKeys. The command stores this object reference in the $Context variable.

The next two commands create PSCloudTask objects by using the New-Object cmdlet. The commands store the tasks in the $Task01 and $Task02 variables.

The final command adds the tasks stored in $Task01 and $Task02 under the job that has the ID Job-000001.

Required Parameters

-BatchContext

Specifies the BatchAccountContext instance that this cmdlet uses to interact with the Batch service. To obtain a BatchAccountContext object that contains access keys for your subscription, use the Get-AzureRmBatchAccountKeys cmdlet.

Type:BatchAccountContext
Position:Named
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False
-Id

Specifies the ID of the task.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-JobId

Specifies the ID of the job under which this cmdlet creates the task.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Optional Parameters

-AffinityInformation

Specifies a locality hint that the Batch service uses to select a node on which to run the task.

Type:PSAffinityInformation
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ApplicationPackageReferences
Type:PSApplicationPackageReference[]
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-CommandLine

Specifies the command line for the task.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Constraints

Specifies the execution constraints that apply to this task.

Type:PSTaskConstraints
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-DependsOn

Specifies that the task depends on other tasks. The task will not be scheduled until all depended-on tasks have completed successfully.

Type:TaskDependencies
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-DisplayName

Specifies the display name of the task.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-EnvironmentSettings

Specifies the environment settings, as key/value pairs, that this cmdlet adds to the task. The key is the environment setting name. The value is the environment setting.

Type:IDictionary
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ExitConditions
Type:PSExitConditions
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Job

Specifies the job under which this cmdlet creates the task. To obtain a PSCloudJob object, use the Get-AzureBatchJob cmdlet.

Type:PSCloudJob
Position:Named
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False
-MultiInstanceSettings

Specifies information about how to run a multi-instance task.

Type:PSMultiInstanceSettings
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ResourceFiles

Specifies resource files, as key/value pairs, that the task requires. The key is the resource file path. The value is the resource file blob source.

Type:IDictionary
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-RunElevated

Indicates that the task process runs with administrator privileges.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Tasks

Specifies the collection of tasks to be added. Each task must have a unique ID.

Type:PSCloudTask[]
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False