8

I'm trying to automate few of our BAT script and for this our script need to know the private IP of each instances of VMSS(no public IP for instances).

Is there a way to query the private IP of all instances under a particular VMSS using azure cli. I tried few command of LB and VMSS but didn't find a solution yet.

az vmss show -g <rg> -n <vmss>
az vmss list-instances -g <rg> -n <vmss>
az vmss nic list-vm-nics -g <rg> --vmss-name <vmss> --ids <id>
az network lb address-pool list -g <rg> --lb-name <lb>
az vmss list-instance-connection-info -g <rg> -n <vmss>

Any help is highly appreciable and I'm not looking for powershell.

lambodar
  • 3,495
  • 5
  • 34
  • 58

1 Answers1

9

You can use the Azure CLI and bash command:

az vmss nic list -g groupName --vmss-name ScaleSetName | grep -w "privateIpAddress"

It can show all the private ips like this:

"privateIpAddress": "192.168.1.4",
"privateIpAddress": "192.168.1.5",
Optimus Prime
  • 6,817
  • 5
  • 32
  • 60
Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • 3
    @ChrisBlom answer is awesome, to add to that the private IP param seems changed the the following: `az vmss nic list --resource-group ec-prod-rg --vmss-name ecprodwebvmss --query "[].ipConfigurations[].privateIpAddress`, you can find the first private IP address by changing both `[]` to `[0]` – Ng Sek Long May 12 '20 at 02:19
  • I had to change the casing on `privateIPAddress` (capital `IP`) and then this worked great. – Michael Haren Aug 16 '23 at 17:16