I am attempting to use the REST API v3 via Powershell to get a list of all assets in Service Desk. However, I would like to pre-filter this list, since we have well over 2,000 assets listed, most of which are not relevant to my needs. I would like to filter by a specific product name.
Here is how I am currently fetching:
- [int]$index = "1"
- while (!$check) {
- $input = @"
- {
- "list_info": {
- "row_count": 100,
- "start_index": $index,
- "sort_field": "name",
- "sort_order": "desc",
- "get_total_count": true,
- }
- }
- }
- "@
- $header = @{TECHNICIAN_KEY=$ApiKey}
- $params = @{input_data=$input;format='json'}
- $Uri = $SdpUri + "/api/v3/assets"
- $result = Invoke-RestMethod -Method GET -Uri $Uri -Headers $header -Body $params -ContentType "application/x-www-form-urlencoded"
- if ($result) {
- $result.assets | Select-Object name,@{n="Product";e={$_.product.name}},@{n="User";e={$_.user.name}} | Where-Object {$_.product -like "*7070*"}
- $index = $index+100
- }
- Else {
- $check = $true
- Write-Host "Ending run"
- break
- }
- }
This relies on post-processing the data to get what I want, which is extremely time consuming and resource intensive.
is there a way that I can add an option to to the JSON input pre-filter to get only the computer assets that I want based on model? The property name on the Powershell output is Product.Name.