// Create a Batch pool and submit a task (C#)
using Microsoft.Azure.Batch;
using Microsoft.Azure.Batch.Auth;
using Microsoft.Azure.Batch.Common;
var credentials = new BatchSharedKeyCredentials(
batchUrl: "https://mybatchaccount.region.batch.azure.com",
accountName: "mybatchaccount",
accountKey: "myAccountKey");
using var client = BatchClient.Open(credentials);
var poolId = "myPool";
client.PoolOperations.CreatePool(
poolId: poolId,
targetDedicatedComputeNodes: 2,
virtualMachineSize: "Standard_A1_v2",
cloudServiceConfiguration: new CloudServiceConfiguration(osFamily: "5"))
.Commit();
var jobId = "myJob";
client.JobOperations.CreateJob(
jobId: jobId,
new JobSpecification { PoolInformation = new PoolInformation { PoolId = poolId } })
.Commit();
var task = new CloudTask("task1", "cmd /c echo Hello Batch!")
{
ResourceFiles = new List
{
ResourceFile.FromUrl("https://myaccount.blob.core.windows.net/scripts/script.ps1", "script.ps1")
}
};
client.JobOperations.AddTask(jobId, task);
© 2025 Microsoft. All rights reserved.