1

I'm trying to set Azure Batch pool start task via powershell and Az module . Need to set ReosurceFiles but cannot create object for it System.Collections.Generic.IList[Microsoft.Azure.Commands.Batch.Models.PSResourceFile]

New-AzBatchResourceFile - is not applicable because it creates Microsoft.Azure.Commands.Batch.Models.PSResourceFile object type

And when I'm trying to use I catch this error:

Exception setting "ResourceFiles": "Cannot convert the "Microsoft.Azure.Commands.Batch.Models.PSResourceFile" value of type "Microsoft.Azure.Commands.Batch.Models.PSResourceFile" to type "System.Collections.Generic.IList`1[Microsoft.Azure.Commands.Batch.Models.PSResourceFile]"." At line:1 char:1 $StartTask.ResourceFiles = $file

   CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
   FullyQualifiedErrorId : ExceptionWhenSetting

Here is full PSell code:

#Set Pool settings
$StartTask = New-Object Microsoft.Azure.Commands.Batch.Models.PSStartTask
$UserIdentity = New-Object Microsoft.Azure.Commands.Batch.Models.PSAutoUserSpecification -ArgumentList @("Task", "Admin")
$task= "/bin/sh -c `"~/blob2.sh $adadmin $publickey $accountName $accountKey $containerName`""
$StartTask.CommandLine = "$task"
$StartTask.MaxTaskRetryCount = 2
$StartTask.WaitForSuccess = $true
$StartTask.UserIdentity = $UserIdentity
$file = New-AzBatchResourceFile -HttpUrl "https://$accountName.blob.core.windows.net/scripts/blob2.sh" -FilePath "blob2.sh"
$StartTask.ResourceFiles = $file
$Pool.StartTask = $StartTask
Set-AzBatchPool -Pool $Pool -BatchContext $ctx
T SOLvic
  • 11
  • 2
  • Did you ever find a solution to this? I cannot modify the ResourceFiles property of the start task, no matter what i do. – Ran Sagy May 10 '21 at 16:04

1 Answers1

-1

You could try thin in the above code :

$files = @()
$file = New-AzBatchResourceFile -HttpUrl "https://$accountName.blob.core.windows.net/scripts/blob2.sh" -FilePath "blob2.sh"
$files += $file
$StartTask.ResourceFiles = $files

Explanation, $files is a generic list to which I am adding the $file of type Microsoft.Azure.Commands.Batch.Models.PSResourceFile

Satya V
  • 3,811
  • 1
  • 6
  • 9
  • This does not seem to work; The type ResourceFiles is expecting is a generic List with a generic type of PSResourceFile - It doesn't accept the genric object[] that @() generates. – Ran Sagy May 10 '21 at 16:05