Using filters

The parameter -filter, that is supported by many cmdlets, allows to restrict the count of objects that are returned by the BLS. In contrast you can filter objects completely on the client side by applying the cmdlet Where-Object to the pipeline. But in general you might gain performance by using the -filter parameter.


The filter provided by the parameter -filter is evaluated by the server itself. Depending on the query this reduces the amount of objects that are needed to send back to the client dramatically. In the other case the usage of the cmdlet Where-Object requires to send all objects (e.g. of a given type) back to the client in a first step. In a second step the cmdlet discards all objects that do not match the filter. That means a lot of objects have to be fetched and transferred over the network, but only a few of them are of interest. Keeping this in mind, it often makes sense to use the parameter -filter.


In the context of the PowerShell Extensions for Ivanti DSM a filter is a fragment of an LDAP query. You might already be familiar with this kind of filters. They are used in the DSMC, where they can be accessed in the object window by clicking the button "Create Filter".


For instance, if you are interested in all computers in the organization unit "Managed Users & Computers" that have a non empty vendor field in their basic inventory, use the following LDAP filter:


(&(!(BasicInventory.Vendor:IsNull=))(SchemaTag=Computer))


You do not have to learn the syntax of LDAP queries to use them in PowerShell scripts. The DSMC provides a graphical interface, the LDAP Query Editor, to assemble such LDAP queries. After putting together the query and closing the editor please click into the field named "Free LDAP" to complete the query string. Now you can copy and paste the query into your PowerShell script.  




Hint: The LDAP Query Editor uses the filter criterion "objectClass", whilst we use the criterion "SchemaTag" throughout this document. Both are equivalent in the context of the DSM 2022.2 SOAP interface.


The following PowerShell command is equivalent to the example depicted above:


Get-ChildItem -Recurse -Filter "(&(!(BasicInventory.Vendor:IsNull=))(SchemaTag=Computer))"


If you use the more specific Get-cmdlets, e.g. Get-EmdbComputer, Get-EmdbSoftwarePackage etc., you can omit the object class. The next example should retrieve the same objects as the previous example:


Get-EmdbComputer -Recurse -Filter "!(BasicInventory.Vendor:IsNull=)"