Skip to content

CMS_AddCustomInventory

Adds a persistent CustomInventory row to the database, meaning that the data will not be flushed out the next time that the CustomInventory package is run.

CMS_AddCustomInventory(category, entry, value, valuetype)

Category name

variable name

value (string)

If you are inserting a Time (valuetype: “T”) it must be set in epoch-time, meaning seconds since January 1. 1970. The scripting library has a function called GetEpochTime, which will convert a date to seconds from 1-1-1970.

If you want to use ‘now’ as the value, you can either insert;

  • an empty string (“”)
  • or the value (“0”)

The type of the value

Valid valuetypes are;

  • “S” for string
  • “I” for integer
  • “T” for time

Boolean, TRUE if function completed successfully.

If bStatus Then bStatus = CMS_AddCustomInventory("Customer Inventory", "Install time packages", "112", "I")
If bStatus Then bStatus = CMS_AddCustomInventory("Bitlocker", "TPM Chip - Enabled", "True", "S")
If bStatus Then bStatus = CMS_AddCustomInventory("Bitlocker", "TPM Chip - Manufactured", "1694973146", "T")

Scripting Guidelines

Handling concurrent execution in PowerPacks

Section titled “Handling concurrent execution in PowerPacks”
Terminal window
function Add-CustomInventoryWithRetry {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$Category,
[Parameter(Mandatory = $true)]
[string]$Entry,
[Parameter(Mandatory = $true)]
[AllowNull()]
[object]$Value,
[Parameter(Mandatory = $true)]
[string]$ValueType,
[int]$MaxAttempts = 10,
[int]$SleepSeconds = 3
)
if ($MaxAttempts -lt 1) {
$MaxAttempts = 1
}
if ($SleepSeconds -lt 1) {
$SleepSeconds = 1
}
for ($attempt = 1; $attempt -le $MaxAttempts; $attempt++) {
try {
CMS_AddCustomInventory -category $Category -entry $Entry -value $Value -valuetype $ValueType
return
} catch {
$errorMessage = $_.Exception.Message
if ($attempt -ge $MaxAttempts) {
$cs.Job_WriteLog("CMS_AddCustomInventory failed for entry '$Entry' after $MaxAttempts attempts. Last error: $errorMessage")
throw
}
$cs.Job_WriteLog("CMS_AddCustomInventory failed for entry '$Entry' (attempt $attempt/$MaxAttempts). Retrying in $SleepSeconds seconds. Error: $errorMessage")
Start-Sleep -Seconds $SleepSeconds
}
}
}

CMS_RemoveCustomInventory Constants Package Property Variables Business Unit support