Find a free IP address in Azure

Whether with automated deployment or when creating a load balancer in Azure. Finding a free IP address is unfortunately not an easy task with the existing cmdlets.
Test-AzureRmPrivateIPAddressAvailability
A popular way to archive that is to use the cmdlet Test-AzureRmPrivateIPAddressAvailability
. It returns the value TRUE or FALSE when specifying the network and an IP address. Some people now loop through every network address in a subnet until a free IP address is confirmed by TRUE.
That’s not only slow, it’s unnecessary. The cmdlet additionally returns a property “AvailableIPAddresses”. This property contains the next 5 free IP addresses.
Get-AzSRFreeIPAddress
However, this cmdlet has one shortcoming. Only the specified subnet is checked. With my cmdlet Get-AzSRFreeIPAddress
you not only get the free IP addresses from a subnet, but if you want and the parameter Subnet is not specified, you get all free IP addresses from every available subnets.
Of course you can also get only a certain number of IP addresses. With the parameter -First
the desired number can be defined.