Extracting Properties from Get-AzureRMNetworkInterface

This topic contains 7 replies, has 3 voices, and was last updated by  Alok Maheshwari 4 months, 3 weeks ago.

  • Author
    Posts
  • #71783

    Alok Maheshwari
    Participant

    Team,

    I am working on a reporting script and i need to extract lot of information from Azure PS cmdlet "Get-azurermnetworkinterface" follwoing is a sample of the output this cmdlet returns for a single NIC.

    now I have several NICs and i am unable to find a way to extract properties like PrivateIPAddress, PrivateIPAddressAllocationMethod etc. basically i face issues with extracting nested properties. i want to send them to a excel sheet which pops on the screen right after i run the script. i have done this for Name, ResourceGrupName, Location etc.
    plesae suggest how can i extract nested properties.

    Name : dhk-sdwec
    ResourceGroupName : HKDR-RG01
    Location : eastasia
    Id : /subscriptions//resourceGroups//providers/Microsoft.Network/networkInterfaces/sdedhk-csha1c1sql581dfe
    Etag : W/"9c2b13ff-5a2c-4d54-9760-1bce7aea475d"
    ResourceGuid : 359a46d8-15c7-4d94-b4d6-sdfawesvasde08098
    ProvisioningState : Succeeded
    Tags :
    VirtualMachine : {
    "Id": "/subscriptions/53d36695-014d-4471-b844-ef2204ae5868/resourceGroups/HKDR-RG01/providers/Microsoft.Compute/virtualMachines/DHK-CSHA1C1SQL"
    }
    IpConfigurations : [
    {
    "Name": "ipconfig1",
    "Etag": "W/\""",
    "Id": "IDhere"
    /ipConfigurations/ipconfig1",
    "PrivateIpAddress": "10.X.X.X",
    "PrivateIpAllocationMethod": "Static",
    "Subnet": {
    "Id": "",
    "ResourceNavigationLinks": []
    },
    "ProvisioningState": "Succeeded",
    "PrivateIpAddressVersion": "IPv4",
    "LoadBalancerBackendAddressPools": [],
    "LoadBalancerInboundNatRules": [],
    "Primary": true,
    "ApplicationGatewayBackendAddressPools": []
    }
    ]
    DnsSettings : {
    "DnsServers": [],
    "AppliedDnsServers": [],
    "InternalDomainNameSuffix":
    }
    EnableIPForwarding : False
    EnableAcceleratedNetworking : False
    NetworkSecurityGroup : {
    "Id":
    "/subscriptions/53d36695-sdfe-4471-b844-ef2204aeeref/resourceGroups/HKfedDR-ffRG01/providers/Microsoft.Network/networkSecurityGroups/DHKdeva-sdfeCSHA1C1SQL-nsg"
    }
    Primary : True

  • #71846

    Liam Kemp
    Participant

    Hi Alok,

    Try referencing the nested property's name. Sort of like this

    $NIC.IPConfigurations['PrivateIPAddress']
    $NIC.IPConfigurations['PrivateIPAllocationMethod']
    

    Liam

    • #71902

      Stephen Valdinger
      Participant

      Is that.....JSON? I've never seen a cmdlet return JSON as it's default output before. Let me know if I am correct on that output type, and if I am, I have an idea!

    • #71908

      Alok Maheshwari
      Participant

      Hello Stephen,

      yes it is JSON, Many Azure Cmdlet return JSON.

    • #71915

      Alok Maheshwari
      Participant

      Hello Lian
      I tried what you suggested, unfortunately didnt work.

      just to explain here is what i am trying to do.

      Get-AzureRmNetworkInterface | foreach {
      $inventoryws.Cells.Item($row, $Column) = $_.ID, $column++
      $inventoryws.Cells.Item($row, $Column) = $_.Name, $column++
      $inventoryws.Cells.Item($row, $Column) = $_.ResourceGroupName, $column++
      $inventoryws.Cells.Item($row, $Column) = $_.IPConfigurations['PrivateIPAddress'], $column++
      }

      I also Tried follwoign to check if suggested method works.

      $IP = get-azurermnetworkinterface
      $IP.IPConfigurations['PrivateIPAddress']

      No Luck!!

  • #71947

    Liam Kemp
    Participant

    Yeah, I haven't tried it with a json string sorry.
    You might want to try using convertfrom-json on the result first, then select what you need from that

    • #71957

      Alok Maheshwari
      Participant

      Hello Liam,

      I tried that this morning, i get "Invalid JSON primitive" error.

      PS C:\users\Alok.Maheshwari\Desktop\test> ConvertFrom-Json -InputObject $in
      ConvertFrom-Json : Invalid JSON primitive: Name.
      At line:1 char:1
      + ConvertFrom-Json -InputObject $in
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
      + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand

      PS C:\users\Alok.Maheshwari\Desktop\test> ConvertFrom-Json -InputObject $in[6]
      ConvertFrom-Json : Invalid JSON primitive: m.
      At line:1 char:1
      + ConvertFrom-Json -InputObject $in[6]
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
      + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand

    • #71974

      Alok Maheshwari
      Participant

      here is what i find out more,

      output 'Type' of Get-azurermnetworkinterface is not JSON, here is what i get when i do Get-azurermnetworkinterface | GM

      TypeName: Microsoft.Azure.Commands.Network.Models.PSNetworkInterface

      maybe that's why convertfrom-JSON not working.

You must be logged in to reply to this topic.