Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
U maakt een verzamelingsvariabele voor een Configuration Manager verzameling door exemplaren van SMS_CollectionVariable Server WMI-klasse toe te voegen aan de CollectionVariables eigenschap van SMS_CollectionSettings Server WMI-klasse.
Een verzamelingsvariabele maken
Stel een verbinding in met de sms-provider. Zie Basisprincipes van sms-provider voor meer informatie.
Een exemplaar van SMS_CollectionSettings downloaden.
Voeg voor elke variabele die moet worden toegevoegd exemplaren van het ingesloten object toe SMS_CollectionVariable aan de matrixeigenschap CollectionVariables .
Sla de wijzigingen op in het
SMS_CollectionSettingsklasse-exemplaar.
Voorbeeld
Met de volgende voorbeeldmethode wordt een verzamelingsvariabele gemaakt en wordt deze toegevoegd aan de verzameling die wordt geïdentificeerd door de opgegeven id. Als het SMS_CollectionSettings object voor de verzameling niet bestaat, wordt het gemaakt.
Zie Codefragmenten van Configuration Manager aanroepen voor meer informatie over het aanroepen van de voorbeeldcode.
Sub CreateCollectionVariable( connection, name, value, mask, collectionId, precedence)
Dim collectionSettings
Dim collectionVariables
Dim collectionVariable
Dim Settings
' See if the settings collection already exists. if it does not, create it.
Set settings = connection.ExecQuery _
("Select * From SMS_CollectionSettings Where CollectionID = '" & collectionID & "'")
If settings.Count = 0 Then
Wscript.Echo "Creating collection settings object"
Set collectionSettings = connection.Get("SMS_CollectionSettings").SpawnInstance_
collectionSettings.CollectionID = collectionId
collectionSettings.Put_
End If
' Get the collection settings object.
Set collectionSettings = connection.Get("SMS_CollectionSettings.CollectionID='" & collectionId &"'" )
' Get the collection variables.
collectionVariables=collectionSettings.CollectionVariables
' Create and populate a new collection variable.
Set collectionVariable = connection.Get("SMS_CollectionVariable").SpawnInstance_
collectionVariable.Name = name
collectionVariable.Value = value
collectionVariable.IsMasked = mask
' Add the new collection variable.
ReDim Preserve collectionVariables (UBound (collectionVariables)+1)
Set collectionVariables(UBound(collectionVariables)) = collectionVariable
collectionSettings.CollectionVariables=collectionVariables
collectionSettings.Put_
End Sub
public void CreateCollectionVariable(
WqlConnectionManager connection,
string name,
string value,
bool mask,
string collectionId,
int precedence)
{
try
{
IResultObject collectionSettings = null;
// Get the collection settings. Create it if necessary.
IResultObject collectionSettingsQuery = connection.QueryProcessor.ExecuteQuery(
"Select * from SMS_CollectionSettings where CollectionID='" + collectionId + "'");
foreach (IResultObject setting in collectionSettingsQuery)
{
collectionSettings = setting;
}
if ( collectionSettings == null)
{
collectionSettings = connection.CreateInstance("SMS_CollectionSettings");
collectionSettings["CollectionID"].StringValue = collectionId;
collectionSettings.Put();
collectionSettings.Get();
}
// Create the collection variable.
List<IResultObject> collectionVariables = collectionSettings.GetArrayItems("CollectionVariables");
IResultObject collectionVariable = connection.CreateEmbeddedObjectInstance("SMS_CollectionVariable");
collectionVariable["Name"].StringValue = name;
collectionVariable["Value"].StringValue = value;
collectionVariable["IsMasked"].BooleanValue = mask;
// Add the collection variable to the collection settings.
collectionVariables.Add(collectionVariable);
collectionSettings.SetArrayItems("CollectionVariables", collectionVariables);
// Set the collection variable precedence.
collectionSettings["CollectionVariablePrecedence"].IntegerValue = precedence;
collectionSettings.Put();
}
catch (SmsException e)
{
Console.WriteLine("Failed to create collection variable: " + e.Message);
throw;
}
}
De voorbeeldmethode heeft de volgende parameters:
| Parameter | Type | Beschrijving |
|---|---|---|
Connection |
- Beheerd: WqlConnectionManager- VBScript: SWbemServices |
Een geldige verbinding met de sms-provider. |
Name |
- Beheerd: String- VBScript: String |
De naam van de variabele die moet worden gemaakt. |
Value |
- Beheerd: String- VBScript: String |
De waarde van de variabele |
Mask |
- Beheerd: Boolean- VBScript: Boolean |
Hiermee geeft u op of de waarde wordt weergegeven in de Configuration Manager-console.true - De variabele waarde wordt niet weergegeven.false - de variabele waarde wordt weergegeven. |
CollectionID |
- Beheerd: String- VBScript: String |
De verzameling waaraan de variabele wordt toegevoegd. |
Precedence |
- Beheerd: Integer- VBScript: Integer |
De prioriteit van de variabele ten opzichte van andere variabelen in de matrix. |
De code compileren
Het C#-voorbeeld heeft de volgende compilatievereisten:
Naamruimten
Systeem
System.Collections.Generic
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
bijeenkomst
microsoft.configurationmanagement.managementprovider
adminui.wqlqueryengine
Robuust programmeren
Zie Info over fouten in Configuration Manager voor meer informatie over foutafhandeling.
.NET Framework-beveiliging
Zie Rolgebaseerd beheer van Configuration Manager voor meer informatie over het beveiligen van Configuration Manager-toepassingen.
Zie ook
Overzicht van objectenVerbinding maken met een SMS-provider in Configuration Manager met behulp van beheerde codeVerbinding maken met een SMS-provider in Configuration Manager met behulp van WMIEen computervariabele maken in Configuration ManagerHoe maak ik een Configuration Manager-object met behulp van beheerde codeEen Configuration Manager-object maken met WMIImplementatie van besturingssysteem Computerbeheer