How to Configure Automatic Software Metering Rule Generation
Updated: November 1, 2013
Applies To: System Center 2012 Configuration Manager, System Center 2012 Configuration Manager SP1, System Center 2012 R2 Configuration Manager
You configure Automatic Software Metering Rule Generation settings, in System Center 2012 R2 Configuration Manager, by modifying the site control file.
Important |
|---|
This setting is shared across the whole hierarchy, and only can be configured on the CAS or a standalone primary site. |
To configure automatic software metering rule generation
Set up a connection to the SMS Provider.
Make a connection to the Software Metering Client Agent section of the site control file by using the SMS_SCI_ClientComp class.
Loop through the array of available properties, making changes as needed.
Commit the property changes to the site control file.
Example
The following example method configures various Software Metering Rule Generation settings by using the SMS_SCI_ClientComp class to connect to the site control file and change properties.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Sub ConfigureAutomaticSWMRuleGeneration(swbemServices, _
swbemContext, _
siteCode, _
enableAutoCreateDisabledRule, _
newAutoCreatePercentage, _
newAutoCreateThreshold)
' Load site control file and get the SMS_SCI_ClientComp section.
swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Refresh", , , swbemContext
Query = "SELECT * FROM SMS_SCI_ClientComp " & _
"WHERE ClientComponentName = 'Software Metering 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
'Loop through the array of embedded SMS_EmbeddedProperty instances.
For Each vProperty In SCIComponent.Props
' Setting: Auto Create Disabled Rule
If vProperty.PropertyName = "Auto Create Disabled Rule" Then
wscript.echo " "
wscript.echo vProperty.PropertyName
wscript.echo "Current value " & vProperty.Value
'Modify the value.
vProperty.Value = enableAutoCreateDisabledRule
wscript.echo "New value " & enableAutoCreateDisabledRule
End If
' Setting: Auto Create Percentage
If vProperty.PropertyName = "Auto Create Percentage" Then
wscript.echo " "
wscript.echo vProperty.PropertyName
wscript.echo "Current value " & vProperty.Value
' Modify the value.
vProperty.Value = newAutoCreatePercentage
wscript.echo "New value " & newAutoCreatePercentage
End If
' Setting: Auto Create Threshold
If vProperty.PropertyName = "Auto Create Threshold" Then
wscript.echo " "
wscript.echo vProperty.PropertyName
wscript.echo "Current value " & vProperty.Value
' Modify the value.
vProperty.Value = newAutoCreateThreshold
wscript.echo "New value " & newAutoCreateThreshold
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 ConfigureAutomaticSWMRuleGeneration(WqlConnectionManager connection, string siteCode, string enableAutoCreateDisabledRule, string newAutoCreatePercentage, string newAutoCreateThreshold) { try { IResultObject siteDefinition = connection.GetInstance(@"SMS_SCI_ClientComp.FileType=1,ItemType='Client Component',SiteCode='" + siteCode + "',ItemName='Software Metering Agent'"); foreach (KeyValuePair<string, IResultObject> kvp in siteDefinition.EmbeddedProperties) { // Create temporary working copy of embedded properties. Dictionary<string, IResultObject> embeddedProperties = siteDefinition.EmbeddedProperties; //Console.WriteLine(kvp.Value.PropertyList["PropertyName"]); // Setting: Auto Create Disabled Rule if (kvp.Value.PropertyList["PropertyName"] == "Auto Create Disabled Rule") { Console.WriteLine(); Console.WriteLine(kvp.Value.PropertyList["PropertyName"]); Console.WriteLine("Current value: " + embeddedProperties["Auto Create Disabled Rule"]["Value"].StringValue); // Change value using the enableAutoCreateDisabledRule value passed in. embeddedProperties["Auto Create Disabled Rule"]["Value"].StringValue = enableAutoCreateDisabledRule; Console.WriteLine("New value : " + enableAutoCreateDisabledRule); } // Setting: Auto Create Percentage if (kvp.Value.PropertyList["PropertyName"] == "Auto Create Percentage") { Console.WriteLine(); Console.WriteLine(kvp.Value.PropertyList["PropertyName"]); Console.WriteLine("Current value: " + embeddedProperties["Auto Create Percentage"]["Value"].StringValue); // Change value using the newAutoCreatePercentage value passed in. embeddedProperties["Auto Create Percentage"]["Value"].StringValue = newAutoCreatePercentage; Console.WriteLine("New value : " + newAutoCreatePercentage); } // Setting: Auto Create Threshold if (kvp.Value.PropertyList["PropertyName"] == "Auto Create Threshold") { Console.WriteLine(); Console.WriteLine(kvp.Value.PropertyList["PropertyName"]); Console.WriteLine("Current value: " + embeddedProperties["Auto Create Threshold"]["Value"].StringValue); // Change value using the newAutoCreateThreshold value passed in. embeddedProperties["Auto Create Threshold"]["Value"].StringValue = newAutoCreateThreshold; Console.WriteLine("New value : " + newAutoCreateThreshold); } // 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; } }
Compiling the Code
This C# example requires:
System
System.Collections.Generic
System.Text
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
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.
System Center 2012 R2 Configuration Manager SDK
Configuration Manager Software Metering
About the Configuration Manager Site Control File
How to Read and Write to the Configuration Manager Site Control File by Using Managed Code
How to Read and Write to the Configuration Manager Site Control File by Using WMI
SMS_SCI_Component Server WMI Class

The example method has the following parameters:
Parameter
Type
Description
connection
Managed: WqlConnectionManager
VBScript: SWbemServices
A valid connection to the SMS Provider.
swbemContext
VBScript: SWbemContext
A valid context object. For more information, see How to Add a Configuration Manager Context Qualifier by Using WMI.
siteCode
Managed: String
VBScript: String
The site code.
enableAutoCreateDisabledRule
Managed: String
VBScript: String
Enables or disables Software Metering auto rule creation.
0 - Disabled
1 - Enabled
newAutoCreatePercentage
Managed: String
VBScript: String
Sets the auto creation percentage.
0 - 100
newAutoCreateThreshold
Managed: String
VBScript: String
Sets the auto creation threshold.