Skip to content

Getting Started with Custom Inventory

Custom inventory is your own data about your Windows endpoints, for example the office an endpoint belongs to. A script writes the data on the endpoint, and the CapaOne Agent sends it with its hardware inventory. CapaOne shows it on the endpoint’s page, under Inventory → Custom.

In this walkthrough, you create a script that writes custom inventory, run it on a test endpoint, and remove the data again.

  1. Go to Windows → Applications and select the Scripts tab.
  2. Click New.
  3. Enter a Name, for example Custom Inventory Demo, and a Version, for example 1.0.
  4. Under PowerBricks, click Open PowerBrick Editor.
  5. Search for Execute PowerShell Snippet, and add it to the Install tab of the Execution Sequence.
  6. Add a second Execute PowerShell Snippet to the Uninstall tab. It removes the demo data when you uninstall the script.

Leave the editor open for the next step. Create a Script describes the script’s other settings, and Execute PowerShell Snippet describes the brick.

The code uses the custom inventory functions of the PowerShell Scripting Library, which you call in the snippet as $cs.CustomInventory_*. It writes two categories:

  • Office is a category without instances. The endpoint has one set of values, written with the instance ''. Replace the values with your own, for example in one script per office.
  • Printers is a category with instances: one instance per printer, with its driver, its port, and whether it’s shared. The code also removes printers that are gone since the script last ran.
  1. Open the brick on the Install tab, and paste this code into PowerShell Snippet:

    Terminal window
    # A category without instances: one set of values for the device.
    # Replace the values with your own, for example in one script per office.
    $cs.CustomInventory_SetValue('Office', '', 'City', 'Copenhagen')
    $cs.CustomInventory_SetValue('Office', '', 'Floor', 3)
    $cs.CustomInventory_SetValue('Office', '', 'Has Parking', $true)
    # A category with instances: one instance per printer.
    $printers = @{}
    foreach ($printer in Get-Printer -ErrorAction SilentlyContinue) {
    # Names can only contain letters, digits, spaces and -, so replace other characters with a space.
    $instance = ($printer.Name -replace '[^\p{L}\p{Nd} -]', ' ' -replace ' {2,}', ' ').Trim()
    $printers[$instance] = $true
    $cs.CustomInventory_SetValue('Printers', $instance, 'Driver', $printer.DriverName)
    $cs.CustomInventory_SetValue('Printers', $instance, 'Port', $printer.PortName)
    $cs.CustomInventory_SetValue('Printers', $instance, 'Shared', $printer.Shared)
    }
    # Remove the printers that are gone since the script last ran.
    foreach ($instance in $cs.CustomInventory_GetInstanceNames('Printers')) {
    if (-not $printers.ContainsKey($instance)) {
    $cs.CustomInventory_RemoveInstance('Printers', $instance)
    }
    }
  2. Click Apply changes.

  3. Open the brick on the Uninstall tab, and paste this code into PowerShell Snippet:

    Terminal window
    $cs.CustomInventory_RemoveCategory('Office')
    $cs.CustomInventory_RemoveCategory('Printers')
  4. Click Apply changes, and then Close.

  5. Click Create. The script is created with the release status Testing.

Category, instance, and value names can only contain letters, digits, spaces, and -. That’s why the code replaces the other characters in printer names: OneNote (Desktop) becomes OneNote Desktop. A name with other characters makes the script fail, and the installation log says which characters aren’t allowed. Open the log with View logs in the endpoint’s row menu on the script’s Endpoints tab.

  1. Open the script, select the Assignment tab, and assign the script to your test endpoint under Direct. CapaOne asks you to confirm, because the script is in Testing. See Assign and Redeploy Windows Applications.
  2. Select the script’s Endpoints tab, and wait until the script has run on the endpoint.
  3. Open the endpoint’s page, open the actions menu (⋮) in the header, point to Request, and select Scan hardware. The agent sends custom inventory with its hardware inventory, so the request delivers it now instead of with the next scan. It can take a few minutes before the data appears.
  4. Select Inventory → Custom.

The Custom tab lists your categories. Office has one card, named after the category, and Printers has one card per printer. Each card ends with Last Updated, the time a value on the card last changed.

Custom sub-tab with the Office category selected, showing City, Floor, Has Parking and Last Updated on one card

Windows endpoint Inventory tab with the Custom sub-tab open, the Office and Printers categories, and Printers selected showing one card per printer (Adobe PDF and Microsoft Print to PDF) with Driver, Port, Shared and Last Updated

The values stay on the endpoint until a script removes them, and the agent sends them with every hardware inventory. The script itself runs once on each endpoint that it’s assigned to.

There’s no separate scan for custom inventory. To send the latest values right away, open the endpoint’s page and select Request → Scan hardware.

To run the script again, for example every week so the list of printers stays current, use a workflow with the Install script action and Redeploy if assigned. See Repeat a Company App or script on a schedule.

  1. On the script’s Endpoints tab, open the endpoint’s row menu and select Uninstall. The Uninstall sequence removes both categories.
  2. When the script has been uninstalled, open the endpoint’s page and select Request → Scan hardware again.

The endpoint’s Custom tab shows No Custom Inventory again, unless other scripts write custom inventory on the endpoint.

Method invocation failed: CustomInventory_* method not found

Section titled “Method invocation failed: CustomInventory_* method not found”

The script fails, and the installation log shows an error like this one:

Method invocation failed because [CapaOne.ScriptingLibrary] does not contain a method named 'CustomInventory_SetValue'.

The script ran with a version of the PowerShell Scripting Library that doesn’t have the custom inventory functions. First, check the agent version of the endpoint where the script failed: go to Windows → Endpoints → List, and use the column picker to show the Agent Version column. You can also select ⓘ next to the endpoint’s name on its page.

An older agent doesn’t have the custom inventory functions. You can’t install a newer Scripting Library separately.

  1. Wait for the agent to update automatically, or update it right away:
    1. Open the endpoint’s page, open the actions menu (⋮) in the header, and select Request → Reconfigure agent.
    2. Select View requests, and wait until the request shows Completed.
    3. Select Request → Restart agent.
  2. Run the script again.

The endpoint can still have an older copy of the Scripting Library from before the agent was updated, and the agent then runs scripts with that copy. This only happens on endpoints that ran scripts or packages before the update, so other endpoints with the same agent version can work.

  1. Open the endpoint’s page, open the actions menu (⋮) in the header, and select Request → Restart agent.
  2. Select View requests, and wait until the request shows Completed.
  3. Run the script again.

The script runs without the error, and the script shows Installed on the endpoint. To see the data under Inventory → Custom right away, select Request → Scan hardware.

See Send Requests to a Windows Endpoint.

The script has run, but the endpoint’s Inventory → Custom tab shows No Custom Inventory, or old values.

The agent doesn’t send custom inventory when the script runs. It sends it with the hardware inventory, which the agent collects once a day by default. Until the next hardware scan, the Custom tab shows the data from the last scan.

  1. On the script’s Endpoints tab, check that the script shows Installed on the endpoint. If it shows Failed Install, open the installation log and fix the error first.
  2. Open the endpoint’s page, open the actions menu (⋮), and select Request → Scan hardware.
  3. Select View requests, and wait until the request shows Completed.
  4. Wait a few minutes, and then select Inventory → Custom again.

The Custom tab shows the categories that the script wrote.

If a category or value is still missing, check its name. Names may only contain letters, digits, spaces, and -. The $cs.CustomInventory_* functions reject other names, and the script fails. If a name with other characters gets into the registry in another way, for example a name created in Registry Editor, the agent skips it and writes a warning to the agent log. To get the agent log, select Request → Get logs.

Use the MCP server or the REST API to search, count, and group endpoints by their custom inventory. For example, find the endpoints in the Copenhagen office. A new field can be filtered on within an hour after an endpoint first reports it. See Custom inventory fields.

The PowerShell Scripting Library has these functions for custom inventory:

Function What it does
$cs.CustomInventory_SetValue Writes a value, optionally with a unit such as bytes or date. Creates the category and instance if they don’t exist.
$cs.CustomInventory_GetValue Reads a value without its unit.
$cs.CustomInventory_GetInstance Returns all values of an instance.
$cs.CustomInventory_GetCategory Returns all instances of a category with their values.
$cs.CustomInventory_GetCategoryNames Returns the names of the categories on the endpoint.
$cs.CustomInventory_GetInstanceNames Returns the names of the instances in a category.
$cs.CustomInventory_RemoveValue Removes a value.
$cs.CustomInventory_RemoveInstance Removes an instance with all its values.
$cs.CustomInventory_RemoveCategory Removes a category with all its instances and values.

$cs.CustomInventory_SetValue also describes the names, the units, and the value types in detail.