Home NewsX Bulk delete all the old jobs from the batch account

Bulk delete all the old jobs from the batch account

by info.odysseyx@gmail.com
0 comment 4 views


When you delete a job, all jobs and all job statistics belonging to that job are also deleted. It also ignores the retention period of job data. That is, if a job still contains jobs that are retained on compute nodes, the batch service deletes the job’s job directory and all its contents. When a request to delete a job is received, the batch service sets the job to the deleted state. Any update operations on a job in the deleted state fail with status code 409 (Conflict) and additional information indicating that the job is being deleted.

The PowerShell command below allows you to delete a single task using its task ID.

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

However, if you have a large number of tasks and want to delete them all at once, refer to the PowerShell command below.

# Replace with your Azure Batch account name, resource group, and subscription ID
$accountName = "yourBatchAccountName"
$resourceGroupName = "yourResourceGroupName"

# Authenticate to Azure
Connect-AzAccount

# Get the Batch account context
$batchContext = Get-AzBatchAccount -Name $accountName -ResourceGroupName $resourceGroupName

# Get all batch jobs with creation time before May 2024
# Replace the creation time date accordingly

$jobsForDelete = Get-AzBatchJob -BatchContext $batchContext | Where-Object {$_.CreationTime -lt "2024-05-01"}

# List the jobs
Write-Host "Jobs to be deleted:"
foreach ($job in $jobsForDelete) {
    Write-Host $job.Id
    # Write-Host "Deleting jobs..."
    Remove-AzBatchJob -Id $job.Id -BatchContext $batchContext -Force
}


 

The above script will delete all jobs created before the creation date. You can modify the parameters as per your needs.





Source link

You may also like

Leave a Comment

Our Company

Welcome to OdysseyX, your one-stop destination for the latest news and opportunities across various domains.

Newsletter

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

Laest News

@2024 – All Right Reserved. Designed and Developed by OdysseyX