Compartir a través de


Configuración del inventario de hardware

Establezca la configuración del Agente cliente de inventario de hardware, en Configuration Manager, modificando la configuración necesaria del archivo de control de sitio.

Para modificar la configuración del Agente cliente de inventario de hardware

  1. Configure una conexión con el proveedor de SMS.

  2. Realice una conexión a la sección Agente de cliente de inventario de hardware del archivo de control de sitio mediante la clase SMS_SCI_ClientComp .

  3. Recorra en bucle la matriz de propiedades disponibles, realizando cambios según sea necesario.

  4. Confirme los cambios en el archivo de control de sitio.

Ejemplo:

En el ejemplo siguiente se establece la configuración del Agente cliente de inventario de hardware mediante la clase SMS_SCI_ClientComp para conectarse al archivo de control de sitio y cambiar las propiedades.

Para obtener información sobre cómo llamar al código de ejemplo, vea Llamar a fragmentos de código de Configuration Manager.


Sub ConfigureHardwareInventoryClientAgentSettings(swbemServices,        _  
                                                  swbemContext,         _  
                                                  siteCode,             _  
                                                  newInventorySchedule, _  
                                                  newMIFSize,           _   
                                                  newMIFCollection)  

    ' Load site control file and get the SMS Software Update Point system resource section.  
    swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Refresh", , , swbemContext  

    Query = "SELECT * FROM SMS_SCI_ClientComp " & _  
    "WHERE ClientComponentName = 'Hardware Inventory Agent' " & _  
    "AND SiteCode = '" & siteCode & "'"            

    Set SCIComponentSet = swbemServices.ExecQuery(Query, ,wbemFlagForwardOnly Or wbemFlagReturnImmediately, swbemContext)  

    ' Only one instance is returned from the query.  
    For Each SCIComponent In SCIComponentSet  

        ' Set the client agent by setting the Flags value to 0 or 1 using the enableDisableClientAgent variable.  
        wscript.echo " "  
        wscript.echo "Hardware Inventory Agent"  
        wscript.echo "Current value " &  SCIComponent.Flags  

        ' Modify the value.                  
        SCIComponent.Flags = enableDisableClientAgent  
        wscript.echo "New value " & enableDisableClientAgent  

        'Loop through the array of embedded SMS_EmbeddedProperty instances.  
        For Each vProperty In SCIComponent.Props  

            ' Setting: Inventory Schedule  
            If vProperty.PropertyName = "Inventory Schedule" Then  
                wscript.echo " "  
                wscript.echo vProperty.PropertyName  
                wscript.echo "Current value " &  vProperty.Value2                 

                'Modify the value.  
                vProperty.Value2 = newInventorySchedule  
                wscript.echo "New value " & newInventorySchedule  
            End If  

            ' Setting: Maximum 3rd Party MIF Size  
            If vProperty.PropertyName = "Maximum 3rd Party MIF Size" Then  
                wscript.echo " "  
                wscript.echo vProperty.PropertyName  
                wscript.echo "Current value " &  vProperty.Value                 

                ' Modify the value.  
                vProperty.Value = newMIFSize  
                wscript.echo "New value " & newMIFSize  
            End If  

            ' Setting: MIF Collection  
            If vProperty.PropertyName = "MIF Collection" Then  
                wscript.echo " "  
                wscript.echo vProperty.PropertyName  
                wscript.echo "Current value " &  vProperty.Value                 

                ' Modify the value.  
                vProperty.Value = newMIFCollection  
                wscript.echo "New value " & newMIFCollection  
            End If  

        Next     

        ' Update the component in your copy of the site control file. Get the path  
        'to the updated object, which could be used later to retrieve the instance.  
        Set SCICompPath = SCIComponent.Put_(wbemChangeFlagUpdateOnly, swbemContext)  

    Next  

    ' Commit the change to the actual site control file.  
    Set InParams = swbemServices.Get("SMS_SiteControlFile").Methods_("CommitSCF").InParameters.SpawnInstance_  
    InParams.SiteCode = siteCode  
    swbemServices.ExecMethod "SMS_SiteControlFile", "CommitSCF", InParams, , swbemContext  

End Sub  

public void ConfigureHardwareInventoryClientAgentSettings(WqlConnectionManager connection,  
                                                    string siteCode,  
                                                    string enableDisableClientAgent,  
                                                    string newInventorySchedule,  
                                                    string newMIFSize,  
                                                    string newMIFCollection)  
{  
    try  
    {  
        IResultObject siteDefinition = connection.GetInstance(@"SMS_SCI_ClientComp.FileType=1,ItemType='Client Component',SiteCode='" + siteCode + "',ItemName='Hardware Inventory Agent'");  

        // Setting: Enable Client Agent  
        // Enable or disable the client agent by setting the Flags value to 0 or 1 using the enableDisableClientAgent variable.   
        Console.WriteLine();  
        Console.WriteLine("Hardware Inventory Client Agent");  
        Console.WriteLine("Current value: " + siteDefinition["Flags"].StringValue);  

        // Change value using the enableDisableClientAgent value passed in.   
        siteDefinition["Flags"].StringValue = enableDisableClientAgent;  
        Console.WriteLine("New value    : " + enableDisableClientAgent);  

        foreach (KeyValuePair<string, IResultObject> kvp in siteDefinition.EmbeddedProperties)  
        {  
            // Create temporary working copy of embedded properties.  
            Dictionary<string, IResultObject> embeddedProperties = siteDefinition.EmbeddedProperties;  

            // Setting: Inventory Schedule  
            if (kvp.Value.PropertyList["PropertyName"] == "Inventory Schedule")  
            {  
                Console.WriteLine();  
                Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
                Console.WriteLine("Current value: " + kvp.Value.PropertyList["PropertyName"]);  

                // Change value using the newInventorySchedule value passed in.   
                embeddedProperties["Inventory Schedule"]["Value2"].StringValue = newInventorySchedule;  
                Console.WriteLine("New value    : " + newInventorySchedule);  
            }  

            // Setting: Maximum 3rd Party MIF Size  
            if (kvp.Value.PropertyList["PropertyName"] == "Maximum 3rd Party MIF Size")  
            {  
                Console.WriteLine();  
                Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
                Console.WriteLine("Current value: " + kvp.Value.PropertyList["PropertyName"]);  

                // Change value using the newMIFSize value passed in.   
                embeddedProperties["Maximum 3rd Party MIF Size"]["Value"].StringValue = newMIFSize;  
                Console.WriteLine("New value    : " + newMIFSize);  
            }  

            // Setting: MIF Collection  
            if (kvp.Value.PropertyList["PropertyName"] == "MIF Collection")  
            {  
                Console.WriteLine();  
                Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
                Console.WriteLine("Current value: " + kvp.Value.PropertyList["PropertyName"]);  

                // Change value using the newMIFCollection value passed in.   
                embeddedProperties["MIF Collection"]["Value"].StringValue = newMIFCollection;  
                Console.WriteLine("New value    : " + newMIFCollection);  
            }  

            // Store the settings that have changed.  
            siteDefinition.EmbeddedProperties = embeddedProperties;  
        }  

        // Save the settings.   
        siteDefinition.Put();  

    }  

    catch (SmsException ex)  
    {  
        Console.WriteLine("Failed. Error: " + ex.InnerException.Message);  
        throw;  
    }  

}  

El método de ejemplo tiene los parámetros siguientes:

Parámetro Tipo Descripción
- connection
- swbemServices
-Administrado: WqlConnectionManager
- VBScript: SWbemServices
Una conexión válida al proveedor de SMS.
swbemContext -Vbscript: SWbemContext Objeto de contexto válido. Para obtener más información, vea Cómo agregar un calificador de contexto de Configuration Manager mediante WMI.
siteCode -Administrado: String
-Vbscript: String
El código del sitio.
enableDisableClientAgent -Administrado: String
-Vbscript: String
Valor para habilitar o deshabilitar el agente cliente.

Deshabilitado: 0

Habilitado: 1
newInventorySchedule -Administrado: String
-Vbscript: String
Valor para establecer la programación de inventario.
newMIFSize -Administrado: String
-Vbscript: String
Valor para establecer el tamaño máximo del MIF de inventario de hardware.

El valor predeterminado es 512.
newMIFCollection -Administrado: String
-Vbscript: String
Valor para habilitar o deshabilitar la colección MIF.

Recoger:

No hay archivos (MIF): 0

Archivos NOIDMIF: 4

Archivos IDMIF: 8

Archivos NOIDMIF e IDMIF: 12

Compilar el código

Este ejemplo de C# requiere:

Espacios de nombres

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Ensamblado

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Programación sólida

Para obtener más información sobre el control de errores, vea Acerca de los errores de Configuration Manager.

Seguridad de .NET Framework

Para obtener más información sobre la protección de aplicaciones Configuration Manager, consulte Configuration Manager administración basada en roles.

Consulta también

Acerca de Configuration Manager Inventario
Acerca del archivo de control de sitio Configuration Manager
Cómo leer y escribir en el archivo de control de sitio Configuration Manager mediante código administrado
Cómo leer y escribir en el archivo de control de sitio Configuration Manager mediante WMI
SMS_SCI_Component clase WMI de servidor
Acerca de las programacionesCómo Create un token de programación