0

I'm working on a powershell script to enable virtual machine creation and the maximum number of virtual machines (252) on a devTestLab's subnet : Azure Subnets

I tried to use the IpConfigurations function but it always returns "null" with my subnet unfortunately :

       $subnetCree = Get-AzVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet
            write-host $subnetCree.IpConfigurations
            if ($subnetCree.IpConfigurations -ne $null) {
                  
            $subnetCree.IpConfigurations[0].PrivateIpAddressAllocationMethod = "Dynamic"
            $subnetCree.IpConfigurations[0].ApplicationGatewayBackendAddressPools = @()
            $subnetCree.IpConfigurations[0].ServiceEndpoints = @()
            $subnetCree.IpConfigurations[0].LoadBalancerBackendAddressPools = @()
            $subnetCree.IpConfigurations[0].LoadBalancerInboundNatRules = @()
            $subnetCree.IpConfigurations[0].MaximumVMs = 252
            }else{
                write-host "ip configuration null"
            }

Here is what it returns to me : resultConsole

I also tried with this function :

$subnetCree.MaxVMsPerUser = 252

But I have this result:

Property 'MaxVMsPerUser' could not be found in this object. Verify that it exists and can be set.

Anyone have an idea please? Thanks very much.

  • What does `$subnetCree` output if you write that out to the console, without specifying a sub-object? – Anthony Norwood Feb 13 '23 at 15:40
  • Have you set two machines to the same IP address? – jdweng Feb 13 '23 at 16:11
  • @AnthonyNorwood I verified that $subnetCree was not empty when displayed. Here is the result : Microsoft.Azure.Commands.Network.Models.PSSubnet And $subnetCree.AddressPrefix gave me the correct address 10.24.59.0/24 – Halcoaching Feb 15 '23 at 08:14
  • @jdweng No I didn't – Halcoaching Feb 15 '23 at 08:19
  • I think you need to configure the GateWay. See : https://learn.microsoft.com/en-us/powershell/module/az.network/add-azvirtualnetworkgatewayipconfig?view=azps-9.4.0. You need a route the the subnet and the route is missing or the subnet is private. – jdweng Feb 15 '23 at 09:50
  • @Halcoaching but you're not using `$subnetCree.AddressPrefix` in your script. – Anthony Norwood Feb 15 '23 at 18:56
  • I tried many things but nothing seems to be able to script this option in Az Powershell and there is not a lot of documentation about this. Any idea ? Thank you. – Halcoaching Feb 27 '23 at 07:50

0 Answers0