CMS_AddCustomInventory
Description
Section titled “Description”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.
Syntax
Section titled “Syntax”CMS_AddCustomInventory(category, entry, value, valuetype)[bool] CMS_AddCustomInventory -category <string> -entry <string> -value <string> -valuetype <string>Parameters
Section titled “Parameters”category (String)
Section titled “category (String)”Category name
entry (String)
Section titled “entry (String)”variable name
value (string)
Section titled “value (string)”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”)
valuetype (string)
Section titled “valuetype (string)”The type of the value
Valid valuetypes are;
- “S” for string
- “I” for integer
- “T” for time
Return value
Section titled “Return value”Boolean, TRUE if function completed successfully.
Boolean, TRUE if function completed successfully.
Example
Section titled “Example”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")CMS_AddCustomInventory 'Customer Inventory' 'Install time packages' '112' 'I'
CMS_AddCustomInventory -category 'Bitlocker' -entry 'TPM Chip - Enabled' -value 'True' -valuetype 'S'
if (CMS_AddCustomInventory('Bitlocker' 'TPM Chip - Manufactured' '1694973146' 'T') { $cs.Job_WriteLog("Added", "Bitlocker entry added to Custom inventory")}Handling concurrent execution in PowerPacks
Section titled “Handling concurrent execution in PowerPacks”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 } }}Related functions
Section titled “Related functions”CMS_RemoveCustomInventory Constants Package Property Variables Business Unit support