Skip to content

Instantly share code, notes, and snippets.

@joeypiccola
Created April 27, 2018 21:09
Show Gist options
  • Save joeypiccola/a95bdca28e0ed2f6b9c696212dbed984 to your computer and use it in GitHub Desktop.
Save joeypiccola/a95bdca28e0ed2f6b9c696212dbed984 to your computer and use it in GitHub Desktop.
example json query
$inventory = Get-Content -Path .\vcen_inventory.json | ConvertFrom-Json
# update the datacenters with what is available in the vcenter
Update-ComboBox -ComboBox $combobox2 -Items ($inventory.vcenters | ?{ $_.name -eq $vcenter }).datacenters.
# update the clusters with what is available in the datacenter
Update-ComboBox -ComboBox $combobox3 -Items (($inventory.vcenters | ?{ $_.name -eq $vcenter }).datacenters | ?{ $_.name -eq $datacenter }).clusters.
# update the datastores with what is available in the cluster
$datastores = ((($inventory.vcenters | ?{ $_.name -eq $vcenter }).datacenters | ?{ $_.name -eq $datacenter }).clusters | ?{ $_.name -eq $cluster }).datastoresclusters | select @{ Name = "value"; Expression = { "$($_.name), $([math]::Round($_.freespacegb, 0)) GB free" } }
Update-ComboBox -ComboBox $combobox4 -Items $datastores.value
# update the portgroups with what is available in the cluster
$portgroups = ((($inventory.vcenters | ?{ $_.name -eq $vcenter }).datacenters | ?{ $_.name -eq $datacenter }).clusters | ?{ $_.name -eq $cluster }).vdportgroups | ?{ $_.VlanConfiguration -notlike "*trunk*" } | Select Name, VlanConfiguration, @{ Name = 'VlanID'; Expression = { [int]$_.VlanConfiguration.split(' ')[1] } } | Sort-Object -Property vlanid | select @{ Name = 'value'; Expression = { "$($_.VlanConfiguration), $($_.name)" } }
Update-ComboBox -ComboBox $combobox8 -Items $portgroups.value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment