The theme that repeats is that you’d want to use ‘sets’ wherever possible to query efficiently. If you build the query like
names of bes computers whose (value of result (it, bes property "{mail}") = "email1.example.com")
what happens is, for every BES Computer, we have to go lookup the definition for property “{mail}”, then look up the result from that property, then lookup the value of the result of the property. Often the longest part of this is looking up the property definition, and if you have a thousand endpoints you repeat that lookup a thousand times.
For ease in changing the list of email address to target, we’d build a ‘string set’ of the email addresses first. I don’t have an ‘{email}’ property in my deployment, so for examples’ sake I’m using a different property “DNS Name”, but it’s the same logic.
-
Build a set of values for filtering
set of (
( “endpoint-1.d.domain.home”
; “Cent-1.domain.home”
; “osd.domain.home”
; “dc.d.domain.home”
)
as string as lowercase)
-
Given that a ‘set’ is treated as a single item instead of it’s individual elements, performing a BES Property lookup along with a ‘set’ only looks up the property definition once. I have 4 properties in my list of hostnames to search, but the lookup of the “DNS Name” property only happens once
(
bes properties whose (reserved flag of it and name of it = "DNS Name")
, it
) of
set of (
( "endpoint-1.d.domain.home"
; "Cent-1.domain.home"
; "osd.domain.home"
; "dc.d.domain.home"
)
as string as lowercase)
Next, we’ll want to filter so that we only have the property results for “DNS Name” where the value in that result is contained by the list of hostnames we’re targeting. Here, the ‘values of items 0’ returns the value from the results, which I include just to test that the query works so far:
values of items 0 of
(
results of item 0 of it,
item 1 of it
) whose (value of item 0 of it as string as lowercase is contained by item 1 of it)
of
(
bes properties whose (reserved flag of it and name of it = "DNS Name")
, it)
of set of (
("endpoint-1.d.domain.home"
;"Cent-1.domain.home"
;"osd.domain.home"
;"dc.d.domain.home"
) as string as lowercase)
But, it’s not the values of the BES Result that we want, but the computers that gave those results. Let’s put those computers into a new computer set, and then look up the values of the other properties that we want to retrieve. Finally, I’m going to retrieve two built-in properties, you’d replace these with your custom properties and then refer to them as item 1, item 2, item 3, etc…
(
name of item 0 of it | "No name",
id of item 0 of it as string | "No computer ID",
value of (result (item 0 of it, item 1 of it)) | "None",
value of (result (item 0 of it, item 2 of it)) | "None"
) of
(
elements of item 0 of it,
item 1 of it,
item 2 of it
) of
(
it,
bes properties whose (reserved flag of it and name of it = "Relay"),
bes properties whose (default flag of it and name of it = "Total Size of System Drive")
) of
set of computers of items 0 of
(
results of item 0 of it,
item 1 of it
) whose (value of item 0 of it as string as lowercase is contained by item 1 of it)
of
(
bes properties whose (reserved flag of it and name of it = "DNS Name")
, it)
of set of (
("endpoint-1.d.domain.home"
;"Cent-1.domain.home"
;"osd.domain.home"
;"dc.d.domain.home"
) as string as lowercase)
This gives results like
cent-1.domain.home, 15019766, BES-Root.domain.home:52311, 40524 MB
ENDPOINT-1, 548870062, BES-Root.domain.home:52311, 129168 MB
DC, 1626921079, BES-Root.domain.home:52311, 65167 MB
For what it’s worth, my test instance has around 5k endpoints, and this lookup took 26 milliseconds to complete.