Como configurar a agenda de avaliação de conformidade padrão
Em Configuration Manager, o arquivo de controle de site mantém a configuração para a configuração do site. Esses exemplos de código consultam o item de arquivo de controle de site específico Configuration Management Agent e alteram o valor EvaluationSchedule para definir o agendamento de avaliação do agente cliente.
Para configurar a agenda de avaliação de conformidade padrão
Configure uma conexão com o Provedor de SMS.
Faça uma conexão com a seção Agente de Cliente de Gerenciamento de Configuração Desejada do arquivo de controle do site usando a classe SMS_SCI_ClientComp .
Faça loop pela matriz de propriedades disponíveis, fazendo alterações conforme necessário.
Confirme as alterações no arquivo de controle do site.
Exemplo
O exemplo de código a seguir mostra como alterar o cronograma de avaliação de conformidade padrão para o agente cliente de gerenciamento de configuração.
Para obter informações sobre como chamar o código de exemplo, consulte Chamando Configuration Manager Snippets de Código.
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;
}
}
O método de exemplo tem os seguintes parâmetros:
Parâmetro | Tipo | Descrição |
---|---|---|
connection |
-Gerenciado: WqlConnectionManager - VBScript: SWbemServices |
Uma conexão válida com o provedor de SMS. |
swbemContext |
-Vbscript: SWbemContext |
Um objeto de contexto válido. Para obter mais informações, consulte Como adicionar um qualificador de contexto de Configuration Manager usando o WMI. |
siteCode |
-Gerenciado: String -Vbscript: String |
O código do site. |
newAgentSchedule |
-Gerenciado: String -Vbscript: String |
A nova agenda no formato de cadeia de caracteres. Para obter mais informações, consulte Sobre agendamentos. |
Compilando o código
Namespaces
System
System.Collections.Generic
System.ComponentModel
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
Programação robusta
Para obter mais informações sobre o tratamento de erros, consulte Sobre erros de Configuration Manager.
Segurança do .NET Framework
Para obter mais informações sobre como proteger aplicativos Configuration Manager, consulte Configuration Manager administração baseada em função.
Confira também
Sobre Configurações de Conformidade (DCM) Configuração e Configuração
Sobre o arquivo de controle de site Configuration Manager
Como ler e gravar no arquivo de controle de site Configuration Manager usando código gerenciado
Como ler e gravar no arquivo de controle de site Configuration Manager usando o WMI
Classe WMI do servidor SMS_SCI_ClientComp
Sobre agendamentosComo Create um token de agendamento
Comentários
https://aka.ms/ContentUserFeedback.
Em breve: Ao longo de 2024, eliminaremos os problemas do GitHub como o mecanismo de comentários para conteúdo e o substituiremos por um novo sistema de comentários. Para obter mais informações, consulteEnviar e exibir comentários de