編集

次の方法で共有


Remove-AzBatchJob

Deletes a Batch job.

Syntax

Remove-AzBatchJob
      [-Id] <String>
      [-Force]
      -BatchContext <BatchAccountContext>
      [-DefaultProfile <IAzureContextContainer>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]

Description

The Remove-AzBatchJob cmdlet deletes an Azure Batch job. This cmdlet prompts you for confirmation before it removes a job, unless you specify the Force parameter.

Examples

Example 1: Delete a Batch job

Remove-AzBatchJob -Id "Job-000001" -BatchContext $Context

This command deletes the job that has the ID Job-000001. The command prompts you for confirmation before it deletes the job. Use the Get-AzBatchAccountKey cmdlet to assign a context to the $Context variable.

Example 2: Delete a Batch job without confirmation by using the pipeline

Get-AzBatchJob -Id "Job-000002" -BatchContext $Context | Remove-AzBatchJob -Force -BatchContext $Context

This command gets the job that has the ID Job-000002 by using the Get-AzBatchJob cmdlet. The command passes that job to the current cmdlet by using the pipeline operator. The command deletes that job. Because the command includes the Force parameter, it does not prompt you for confirmation.

Example 3: Loop through all jobs and delete

# Get context
$accountname = "PUT YOUR AZURE BATCH ACCOUNT NAME HERE"
$batchcontext = Get-AzBatchAccount -AccountName $accountname

# Get jobs
$jobs = Get-AzBatchJob -BatchContext $batchcontext

# Loop through jobs
foreach ($element in $jobs) {
	Write-Host "Processing "$element.Id
	Remove-AzBatchJob -Id $element.Id -BatchContext $batchcontext -Force -Confirm:$false
}

The commands above Remove all of the jobs for a given Azure Batch account. Because the command includes the Force parameter, it does not prompt you for confirmation.

Parameters

-BatchContext

Specifies the BatchAccountContext instance that this cmdlet uses to interact with the Batch service. If you use the Get-AzBatchAccount cmdlet to get your BatchAccountContext, then Microsoft Entra authentication will be used when interacting with the Batch service. To use shared key authentication instead, use the Get-AzBatchAccountKey cmdlet to get a BatchAccountContext object with its access keys populated. When using shared key authentication, the primary access key is used by default. To change the key to use, set the BatchAccountContext.KeyInUse property.

Type:BatchAccountContext
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with azure.

Type:IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Force

Forces the command to run without asking for user confirmation.

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

-Id

Specifies the ID of the job that this cmdlet deletes. You cannot specify wildcard characters.

Type:String
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-WhatIf

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

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

String

BatchAccountContext

Outputs

Void