Forum Discussion

Alan2022's avatar
Alan2022
Iron Contributor
May 11, 2022
Solved

Do you have any faster ps script to get azure private ip address?

Hi Community,   Do you have any faster ps script to get azure private ip address? Extracting too many vms makes this script slow. Thanks.   My Code.   $nin = (Get-AzVM -Name "VMNAME").NetworkP...
  • LainRobertson's avatar
    May 11, 2022

    Alan2022 

     

    Hi, Alan.

     

    Try the following.

     

    It's not necessarily that much better as you are forced to do client-side filtering for IP information (at least with these commandlets) but it should be a bit faster through not having to make two REST calls (one for fetching the VM data, and a second for the interface data.)

     

    Get-AzNetworkInterface | Where-Object { $_.VirtualMachine -and $_.IPConfigurations -and $_.IPConfigurations.PrivateIPAddress } | Select-Object -Property @{n="Name"; e={ $_.VirtualMachine.Id.Split("/")[-1] }}, @{n="PrivateIPAddress"; e= { $_.IpConfigurations.PrivateIPAddress }}

     

    Cheers,

    Lain

Resources