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