How to Reset the Software Inventory Cache

 

Updated: November 1, 2013

Applies To: System Center 2012 Configuration Manager, System Center 2012 Configuration Manager SP1, System Center 2012 R2 Configuration Manager

In System Center 2012 R2 Configuration Manager, you reset the software inventory cache by connecting to the inventory agent namespace and deleting the inventory action status instance for software inventory.

To reset the software inventory cache

  1. Connect to the inventory agent namespace (root\ccm\invagt).

  2. Delete the inventory action status instance for software inventory ({00000000-0000-0000-0000-000000000002}).

Example

The following example method shows how to reset the software inventory cache by connecting to the inventory agent namespace and deleting the inventory action status instance for software inventory.

For information about calling the sample code, see How to Call a Configuration Manager Object Class Method by Using WMI


Sub ResetSoftwareInventoryCache()

    ' Get a connection to the "root\ccm\invagt" namespace.
    Dim locator
    Set locator = CreateObject("WbemScripting.SWbemLocator")
    Dim services
    Set services = locator.ConnectServer( , "root\ccm\invagt")

    ' Delete the specified InventoryActionStatus instance.
    services.Delete "InventoryActionStatus.InventoryActionID='{00000000-0000-0000-0000-000000000002}'"      

    ' Display message.
    wscript.echo "Reset Software Inventory cache."

End Sub


public void ResetSoftwareInventoryCache()
{
    try
    {
        // Define the scope (namespace).
        ManagementScope inventoryAgentScope = new ManagementScope(@"root\ccm\invagt");

        // Load the class that you want to work with.
        ManagementClass inventoryClass = new ManagementClass(inventoryAgentScope.Path.Path, "InventoryActionStatus", null);

        // Query the class for the InventoryActionID object (create query, create searcher object, execute query).
        ObjectQuery query = new ObjectQuery("SELECT * FROM InventoryActionStatus WHERE InventoryActionID = '{00000000-0000-0000-0000-000000000002}'");
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(inventoryAgentScope, query);
        ManagementObjectCollection queryResults = searcher.Get();

        // Enumerate the collection to get to the result (there should only be one item returned from the query).
        foreach (ManagementObject result in queryResults)
        {
            // Display message and delete the object.
            Console.WriteLine("Resetting Software Inventory cache.");
            result.Delete();
        }
    }

    catch (System.Management.ManagementException ex)
    {
        Console.WriteLine("Failed to run action. Error: " + ex.Message);
        throw;
    }
}

Compiling the Code

This C# example requires:

System.Management

Robust Programming

For more information about error handling, see About Configuration Manager Errors.

.NET Framework Security

For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.

Show: