VMware Cloud Community
DDtAM
Contributor
Contributor

Imported json - how do I specify a dup object name

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!

0 Kudos
4 Replies
Zsoldier
Expert
Expert

$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.

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
0 Kudos
LucD
Leadership
Leadership

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
DDtAM
Contributor
Contributor

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
}

0 Kudos
DDtAM
Contributor
Contributor

Thank you... This worked!

I was so close... LOL

0 Kudos