Unable to map usermanged public ip to azure batch pool using powershell

Biswajit Samal 21 Reputation points
2022-08-02T05:51:59.853+00:00

I am try to add map usermanaged public ip to batch pool using powershell script. I am able to map same ip using azure portal but getting error while doing through powershell.

Error:
StatusMessage: The value provided for one of the properties in the request body is invalid.
ClientRequestId:
RequestId: 5d56541b-ed66-4dec-a14f-047b6bd6fcd1

Error code: InvalidPropertyValue
Message: The value provided for one of the properties in the request body is invalid.
RequestId:5d56541b-ed66-4dec-a14f-047b6bd6fcd1
Time:2022-08-02T05:31:19.2907591Z
Error details:
PropertyName: provision
PropertyValue: UserManaged
Reason: No public IPAddressIds specified for user managed provision

Script

$PoolId = "test-pool"  
$VirtualMachineSize = "Standard_D2s_v3"  
$Context = Get-AzBatchAccount -AccountName "testbatch"  
  
$ImageRef = New-Object Microsoft.Azure.Commands.Batch.Models.PSImageReference -ArgumentList @("WindowsServer", "MicrosoftWindowsServer", "2022-datacenter-smalldisk", "latest")  
  
$AutoScaleFormula = 'startingNumberOfVMs = 1; maxNumberofVMs = 5; pendingTaskSamplePercent = $PendingTasks.GetSamplePercent(180 * TimeInterval_Second); pendingTaskSamples = pendingTaskSamplePercent <= 0 ? 0 : pendingTaskSamplePercent < 70 ? startingNumberOfVMs : avg($PendingTasks.GetSample(180 * TimeInterval_Second)); $TargetDedicatedNodes=min(maxNumberofVMs, pendingTaskSamples); $NodeDeallocationOption = taskcompletion;'  
  
$Configuration = New-Object Microsoft.Azure.Commands.Batch.Models.PSVirtualMachineConfiguration -ArgumentList @($ImageRef, "batch.node.windows amd64")  
  
$NetworkConfig = New-Object Microsoft.Azure.Commands.Batch.Models.PSNetworkConfiguration  
$SubnetId = "/subscriptions/gc7b6b49-6035-42c9-8607-2892bdae5eq4/resourceGroups/test-rg/providers/Microsoft.Network/virtualNetworks/test-vn/subnets/test-subnet"  
# $IpAddressId = "/subscriptions/gc7b6b49-6035-42c9-8607-2892bdae5eq4/resourceGroups/test-rg/providers/Microsoft.Network/publicIPAddresses/test-ip"  
$Pip = New-Object Microsoft.Azure.Commands.Batch.Models.PSPublicIPAddressConfiguration -ArgumentList @("UserManaged")  
# [String[]]$data = $IpAddressId  
$ip = Get-AzPublicIpAddress -Name "test-ip" -ResourceGroupName "test-rg"  
$IpAddressIds = New-Object System.Collections.Generic.List[string]  
$IpAddressIds.Add($ip.ID)  
$Pip.IpAddressIds = $IpAddressIds  
$NetworkConfig.PublicIPAddressConfiguration = $Pip  
$NetworkConfig.SubnetId = $SubnetId  
  
  
New-AzBatchPool -Id $PoolId `  
    -VirtualMachineSize $VirtualMachineSize `  
    -VirtualMachineConfiguration $Configuration `  
    -AutoScaleFormula $AutoScaleFormula `  
    -BatchContext $Context `  
    -NetworkConfiguration $NetworkConfig  
Azure Batch
Azure Batch
An Azure service that provides cloud-scale job scheduling and compute management.
307 questions
{count} votes