private/Invoke-VexaFilter.ps1
function Invoke-VexaFilter { param ( [string] $Filter ) $Prev = $Global:VexaData.Inventories.Prev if ($Filter.Datacenter) { $Prev.Datacenter = foreach ($Name in $Filter.Datacenter) { $Prev.Datacenter.Where({$_.Name -eq $Name}) } # Remove objects from inventory which are not children of the filtered Datacenter list. $Prev.ClusterComputeResource = $Prev.ClusterComputeResource.Where({ $_.Id -in $Prev.Datacenter.Children }) $Prev.HostSystem = $Prev.HostSystem.Where({ $_.Id -in $Prev.Datacenter.Children }) } if ($Filter.ClusterComputeResource) { $Prev.ClusterComputeResource = foreach ($Name in $Filter.ClusterComputeResource) { $Prev.ClusterComputeResource.Where({$_.Name -eq $Name}) } } $Global:VexaData.Inventories.Prev = $Prev <# # Remove objects from VexaData.Inventories which do not match the filter $PrevInventory = $Global:VexaData.Inventories.Prev foreach ($FilObj in $Filter.Keys) { $Result = foreach ($Value in $Filter.$($FilObj)) { $PrevInventory.$($FilObj).Where({$_.Name -eq $Value}) } $Global:VexaData.Inventories.Prev.$($FilObj) = $Result } # If ClusterComputeResource is specified in the filter and it leaves Datacenter objects # with no related cluster objects then remove the Datacenter object. foreach ($Dc in $Global:VexaData.Inventories.Prev.Datacenter) { if ($Dc.Children.Where({$_ -in $VexaData.Inventories.Prev.ClusterComputeResource.Id}).Count -eq 0) { $Global:VexaData.Inventories.Prev.Datacenter = $Global:VexaData.Inventories.Prev.Datacenter.Where({ $_.Id -ne $Dc.Id }) } }#> } |