Dave_Lee
2 years agoAdvisor
API Filtering
Hi all I’m hoping someone might be able to steer me in the right direction! I’m trying to put together a filter to pull back devices that have: system.azure.tag.environment = production system....
I’m making the API calls from PowerShell, so ended up doing the filtering there. It’s obviously not as efficient as it could be, as I’m retrieving things I don’t actually need from the LM API, but I couldn’t find a way to make it work otherwise.
So I do my query, then loop through each page of results, then filter it as below and process just the items that pass the filter:
$filteredDevices = $devices.items | Where-Object {
($_ | Select -ExpandProperty systemProperties | where-object {$_.name -eq "system.azure.tag.environment"}).value -in $prodTagValues -OR
($_ | Select -ExpandProperty systemProperties | where-object {$_.name -eq "system.azure.tag.environment"}).length -eq 0
}