wpietrzakpl / GlpiTools

PowerShell Module to work with Glpi API
15 stars 8 forks source link

Feature-Request - Could multiple SearchType, SearchValue, SearchField tripples be specified to Search-GlpiToolsItems #21

Closed derry43 closed 2 years ago

derry43 commented 2 years ago

Would it be possible to allow multiple SearchType, SearchValue, SearchField tripples to be specified in the arguments to Search-GlpiToolsItems, allowing more comples searches to be built up. By default these could be linked by an AND criteria.

So for example

Search-GlpiToolsItems -SearchFor Computer -SearchField 31 -SearchType notequal -searchvalue 2 -SearchField 1 -SearchType notcontains -searchvalue "WEST" -SearchField 1 -SearchType notcontains -searchvalue "WEST"

would do a search like

/search/Computer?\criteria[0][link]=AND&criteria[0][field]=31&criteria[0][searchtype]=notequal&criteria[0][value]=2&criteria[1][link]=AND&criteria[1][field]=1&criteria[1][searchtype]=notcontains&criteria[1][value]=WEST

Could also go to more complex searches by allowing use of additional parameters -sAND (search AND) and -sOR (search OR) as follows:

Search-GlpiToolsItems -SearchFor Computer -sAND -SearchField 31 -SearchType notequal -searchvalue 2 -sAND -SearchField 1 -SearchType contains -searchvalue "WEST" -sOR -SearchField 1 -SearchType contains -searchvalue "EAST"

would do a search like

/search/Computer?\criteria[0][link]=AND&criteria[0][field]=31&criteria[0][searchtype]=notequals&criteria[0][value]=2&criteria[1][link]=AND&criteria[1][field]=1&criteria[1][searchtype]=contains&criteria[1][value]=WEST&criteria[2][link]=OR&criteria[2][field]=1&criteria[2][searchtype]=contains&criteria[2][value]=EAST

As you can see, their is an almost 1 to 1 positional match between parameters to Search-GlpiToolsItems and search criteria items, which could allow the API search url parameters to be build up relatively easily

-sAND                => &criteria[0][link]=AND
-SearchField 31      => &criteria[0][field]=31
-SearchType notequal => &criteria[0][searchtype]=notequals
-searchvalue 2       => &criteria[0][value]=2
-sAND                => &criteria[1][link]=AND
-SearchField 1       => &criteria[1][field]=1
-SearchType contains => &criteria[1][searchtype]=contains
-searchvalue "WEST"  => &criteria[1][value]=WEST
-sOR                 => &criteria[2][link]=OR
-SearchField 1       => criteria[2][field]=1
-SearchType contains => &criteria[2][searchtype]=contains
-searchvalue "EAST"  => &criteria[2][value]=EAST
wpietrzakpl commented 2 years ago

Hey, added this to the function https://www.wpietrzak.pl/glpi/SearchFunctionChange/