Skip to content

$cs.CustomInventory_GetInstanceNames

CapaOne

Returns the names of the instances in a custom inventory category. Returns an empty array if the category doesn’t exist. Windows-only.

For how custom inventory is stored in categories, instances and values, see $cs.CustomInventory_SetValue.

$cs.CustomInventory_GetInstanceNames(string category)

Name of the category, for example Installed Applications. Names aren’t case-sensitive. Can’t be empty or longer than 255 characters, and can only contain letters, digits, spaces and -: see Names.

Array of instance names (string[]). A category with only one instance has the instance default. Empty array if the category doesn’t exist. Throws an error if category isn’t valid.

Terminal window
$instances = $cs.CustomInventory_GetInstanceNames('Installed Applications')
$cs.Job_WriteLog("Applications in the custom inventory: $($instances -join ', ')")

Removing the instances of applications that are no longer installed:

Terminal window
foreach ($instance in $cs.CustomInventory_GetInstanceNames('Installed Applications')) {
if (-not (Test-Path "$env:ProgramFiles\$instance")) {
$cs.CustomInventory_RemoveInstance('Installed Applications', $instance)
}
}

$cs.CustomInventory_GetInstance $cs.CustomInventory_GetCategory $cs.CustomInventory_GetCategoryNames