$cs.CustomInventory_GetInstanceNames
Description
Section titled “Description”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.
Syntax
Section titled “Syntax”$cs.CustomInventory_GetInstanceNames(string category)
Parameters
Section titled “Parameters”category (String)
Section titled “category (String)”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.
Return value
Section titled “Return value”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.
Example
Section titled “Example”$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:
foreach ($instance in $cs.CustomInventory_GetInstanceNames('Installed Applications')) { if (-not (Test-Path "$env:ProgramFiles\$instance")) { $cs.CustomInventory_RemoveInstance('Installed Applications', $instance) }}Related functions
Section titled “Related functions”$cs.CustomInventory_GetInstance $cs.CustomInventory_GetCategory $cs.CustomInventory_GetCategoryNames