Configuración de la programación de evaluación de cumplimiento predeterminada

En Configuration Manager, el archivo de control de sitio mantiene la configuración del sitio. Estos ejemplos de código consultan el elemento de archivo de control de sitio específico Agente de administración de configuración y cambian el valor EvaluationSchedule para establecer la programación de evaluación del agente cliente.

Para configurar la programación de evaluación de cumplimiento predeterminada

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

  2. Realice una conexión a la sección Desired Configuration Management Client Agent 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 de código siguiente se muestra cómo cambiar la programación de evaluación de cumplimiento predeterminada para el agente de cliente de administración de configuración.

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


Sub ChangeDCMAgentEvaluationSchedule(swbemServices,    _  
                                     swbemContext,     _  
                                     siteCode,         _  
                                     newAgentSchedule)  

    ' The evaluation schedule is defined by a string stored in a schedule token format.   
    ' Detailed information on the schedule token format can be found in the class SMS_ScheduleToken reference material.  

    ' Load site control file and get DCM client component section.  
swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Refresh", , , swbemContext  
Set swbemInst = swbemServices.Get("SMS_SCI_ClientComp.Filetype=1,Itemtype='Client Component',Sitecode='" & siteCode & "',ItemName='Configuration Management Agent'", , swbemContext)  

    ' Loop through the array of embedded SMS_EmbeddedProperty instances for the   
    ' Number of Retries PropertyName. Get its value and display it.  
    For Each vProperty In swbemInst.Props  

        If vProperty.PropertyName = "EvaluationSchedule" Then  

            ' Display DCM client agent evaluation schedule before change.  
            Wscript.Echo " "  
            Wscript.Echo "Evaluation Schedule - Before Change"  
            Wscript.Echo "-----------------------------------"  
            Wscript.Echo vProperty.Value2  

            ' Set DCM client agent evaluation schedule using the newAgentSchedule variable.  
            vProperty.Value2 = newAgentSchedule  

            ' Save new client agent settings  
            swbemInst.Put_ , swbemContext  
            swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Commit", , , swbemContext  

        End If  
    Next  

    ' Refresh in-memory copy of the site control file and get the DCM client component section.  
swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Refresh", , , swbemContext  
Set swbemInst = Nothing  

Set swbemInst = swbemServices.Get("SMS_SCI_ClientComp.Filetype=1,Itemtype='Client Component',Sitecode='" & siteCode & "',ItemName='Configuration Management Agent'", , swbemContext)  

    For Each vProperty In swbemInst.Props  

        If vProperty.PropertyName = "EvaluationSchedule" Then  

            ' Sisplay DCM client agent evaluation schedule before change.  
            Wscript.Echo " "  
            Wscript.Echo "Evaluation Schedule - After Change"  
            Wscript.Echo "----------------------------------"  
            Wscript.Echo vProperty.Value2  

        End If  
    Next  

End Sub  


public void ChangeDCMAgentEvaluationSchedule(WqlConnectionManager connection,  
                                             string siteCode,  
                                             string newAgentSchedule)  
{  

    // The evaluation schedule is defined by a string stored in a schedule token format.   
    // Detailed information on the schedule token format can be found in the class SMS_ScheduleToken reference material.  

    try  
    {  
        IResultObject siteDefinition = connection.GetInstance(@"SMS_SCI_ClientComp.FileType=1,ItemType='Client Component',SiteCode='" + siteCode + "',ItemName='Configuration Management Agent'");  

        if (siteDefinition.EmbeddedProperties.ContainsKey("EvaluationSchedule"))  
        {  
            Dictionary<string, IResultObject> WorkingEmbeddedProperties = siteDefinition.EmbeddedProperties; //get temporary copy  

            // Display DCM client agent settings before change.  
            Console.WriteLine();  
            Console.WriteLine("DCM Client Agent Schedule - Before Change");  
            Console.WriteLine("-----------------------------------------");               
            Console.WriteLine("Schedule in token format: " + WorkingEmbeddedProperties["EvaluationSchedule"]["Value2"].StringValue);  

            // Set DCM client agent setting to new value.  
            WorkingEmbeddedProperties["EvaluationSchedule"]["Value2"].StringValue = newAgentSchedule;   
            siteDefinition.EmbeddedProperties = WorkingEmbeddedProperties;  

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

            // Verify change by reconnecting and getting the value again.  
            Dictionary<string, IResultObject> WorkingEmbeddedProperties2 = siteDefinition.EmbeddedProperties; //Get temporary copy for change verification.  

            // Display DCM client agent settings after change.  
            Console.WriteLine();  
            Console.WriteLine("DCM Client Agent Schedule - After Change");  
            Console.WriteLine("-----------------------------------------");  
            Console.WriteLine("Schedule in token format: " + WorkingEmbeddedProperties2["EvaluationSchedule"]["Value2"].StringValue);  

        }  
    }  

    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 -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.
newAgentSchedule -Administrado: String
-Vbscript: String
La nueva programación en formato de cadena. Para obtener más información, vea Acerca de las programaciones.

Compilar el código

Espacios de nombres

System

System.Collections.Generic

System.ComponentModel

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 la configuración y configuración de La configuración de la configuración de cumplimiento (DCM)
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_ClientComp clase WMI de servidor
Acerca de las programacionesCómo Create un token de programación