Unable to create constructor for Azure Batch PSPoolEndpointConfiguration

Biswajit Samal 21 Reputation points
2022-08-02T11:08:12.927+00:00

Microsoft.Azure.Commands.Batch.Models.PSPoolEndpointConfiguration

public PSPoolEndpointConfiguration (System.Collections.Generic.IReadOnlyList<Microsoft.Azure.Batch.InboundNatPool> inboundNatPools);  

While initializing PSPoolEndpointConfiguration class in powershell, getting below error:

Error
"Cannot convert
| the "Microsoft.Azure.Batch.InboundNatPool" value of type "Microsoft.Azure.Batch.InboundNatPool" to
| type "System.Collections.Generic.IReadOnlyList`1[Microsoft.Azure.Batch.InboundNatPool]"

Script

$NetworkSecurityGroupRules = New-Object System.Collections.Generic.List[Microsoft.Azure.Batch.NetworkSecurityGroupRule]  
$Rule = New-Object Microsoft.Azure.Batch.NetworkSecurityGroupRule -ArgumentList (260, "Deny", "*")  
$NetworkSecurityGroupRules.Add($Rule)  
  
$InboundNatPool = New-Object Microsoft.Azure.Batch.InboundNatPool("Deny_RDP", "Tcp", 3349, 1, 49999, $NetworkSecurityGroupRules)  
$InboundNatPools = New-Object System.Collections.Generic.List``1[Microsoft.Azure.Batch.InboundNatPool]  
$InboundNatPools.Add($InboundNatPool)  
  
$PSPoolEndpointConfiguration = New-Object Microsoft.Azure.Commands.Batch.Models.PSPoolEndpointConfiguration -ArgumentList @($InboundNatPools)  
Azure Batch
Azure Batch
An Azure service that provides cloud-scale job scheduling and compute management.
301 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,358 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 44,776 Reputation points
    2022-08-02T21:58:26.05+00:00

    I don't have any Azure stuff to try, but this should at least demonstrate creating a strongly typed list:

    $InboundNatPools = New-Object System.Collections.Generic.List[string]  
    $InboundNatPools.add("abc")  
    $InboundNatPools.add([decimal]1.23)  
    $InboundNatPools.add(10E2)  
    

    If you examined the object types of each list element you'd see they all have the same type: "string", and the values would be the string representation of the original object because each of them has a "ToString() method so the implicit cast works.

    Give it a try using "[Microsoft.Azure.Batch.InboundNatPool]" in place of "[string]" in the example.

    1 person found this answer helpful.