Automation

 View Only
  • 1.  Imported json - how do I specify a dup object name

    Posted Feb 02, 2018 04:59 PM

    I was able to pull in a json with invoke-webrequest.

    When I look at $x.y.z.ipaddress, it displays two values.  one is our public and one backup.  How can I assign the public IP to $PubIP  There is an object $x.y.z.networkType that defines the public vs backup.

    something like...

    $PubIP = $x.y.z.ipaddress(Where $x.y.z.networktype = public)

    $BkpIP = $x.y.z.ipaddress(Where $x.y.z.networktype = backup)

    Thank you!



  • 2.  RE: Imported json - how do I specify a dup object name

    Posted Feb 02, 2018 05:31 PM

    $PubIP = ($x.y.z | Where-Object {$_.networktype -eq "public"}).ipaddress

    $BkpIP = ($x.y.z | Where-Object {$_.networktype -eq "backup"}).ipaddress

    Probably something like this if I'm extrapolating from your post correctly.



  • 3.  RE: Imported json - how do I specify a dup object name

    Posted Feb 02, 2018 07:15 PM

    Thank you... This worked!

    I was so close... LOL



  • 4.  RE: Imported json - how do I specify a dup object name

    Posted Feb 02, 2018 05:38 PM

    Can you show us the object you imported?
    With something like ' $x.y.z | Format-Custom -Depth 2'



  • 5.  RE: Imported json - how do I specify a dup object name

    Posted Feb 02, 2018 07:08 PM

    This is from $x.y.z | format-custom -depth 2

    class PSCustomObject
    {
      workorder_id =
      serverinfo_id = 36971
      netmask = 255.255.255.0
      default_gw = 10.10.10.1
      ip_address = 10.10.10.78
      id =
      target_hostname =
      network_type = PUBLIC
      suffix =
      port_group =
      server_farm_name =
      seczonename =
      networkinfo_id = 46730
    }

    class PSCustomObject
    {
      workorder_id =
      serverinfo_id = 36971
      netmask = 255.255.255.0
      default_gw = 10.11.11.1
      ip_address = 10.11.11.241
      id =
      target_hostname =
      network_type = BK
      suffix =
      port_group =
      server_farm_name =
      seczonename =
      networkinfo_id = 46731
    }