I would like to get the public IP of an Azure Function in powershell, how this can be done? I saw several examples for VMs but not a function, thanks
-
are you talking about Functions on consumption plan or on App Service plan? – silent Nov 18 '20 at 15:59
Please try the following:
$ips = [System.Net.Dns]::GetHostAddresses("function-getiotdata.azurewebsites.net")
$ips.IPAddressToString
Update:
Also, if you are using a service plan, you can try the following to obtain the outbound IP:
az webapp show --resource-group <group_name> --name <app_name> --query outboundIpAddresses --output tsv
az webapp show --resource-group <group_name> --name <app_name> --query possibleOutboundIpAddresses --output tsv
Please keep in mind that the address might change if you make changes in the service plan, e.g. delete the function, change service tier etc...
-
You need to mention that this does not resolve to the same IP address all the time. Your Function does not have a fixed IP. Also, I kinda suspect the OP might have been asking for the outbound IP of his Function. But they havent replied to my comment – silent Nov 18 '20 at 17:02
-
OK, thanks, it worked but it seems to me that it is giving the internal IP 20.50.2.4! What I was looking for is a powershell commandlet like Get-AzureRMVM.... – eliassal Nov 18 '20 at 17:08
-
Yes indeed, 100% agree, the consumption plan might be a problem. Also the limitation with SO is that we do not have a deeper context why and where this will be used for sure, so it might be completely irrelevant, or answer could be changing the complete approach.. I believe that based on the provided context, maybe eliassal can try to use the commands above and check by him/her self to see if it helps.. – kgalic Nov 18 '20 at 17:11
-
Hi, I used the 1st syntax, getting a long string of IPs separated by commas as follows 51.137.21.195,51.137.20.11,51.137.22.116,51.137.22.194,51.137.23.0,51.137.23.25,40.114.162.30,40.114.162.35,40.114.162.47, so it does not give the public IP of the function – eliassal Nov 19 '20 at 8:34
-