You view monthly usage summary information, in Microsoft System Center Configuration Manager 2007, by using the SMS_MeteredFiles, SMS_MonthlyUsageSummary, SMS_MeteredUser and SMS_R_System classes.

The metering data is only summarized at specified intervals (by default, daily at midnight). Metering data does not appear in the summarized data until the summarization task has run.

To view monthly usage summary information

  1. Set up a connection to the SMS Provider.

  2. Get all the metered files (SMS_MeteredFiles).

  3. Get all the monthly file usage summary information (SMS_MonthlyUsageSummary).

  4. Get all the metered users (SMS_MeteredUser).

  5. Get all the computer names (SMS_R_System).

  6. Loop through the collections, displaying information as required.


The following example method displays file usages summary information by using the SMS_MeteredFiles and SMS_FileUsageSummary classes.

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

Visual Basic Script  Copy Code
Sub ViewMonthlySummary(connection)

	' Get SMS_MeteredFiles - used to match FileID to a file name

		' Build query to get all metered files. 
		meteredFilesQuery = "SELECT * FROM SMS_MeteredFiles"
		' Run query.
		Set meteredFiles = connection.ExecQuery(meteredFilesQuery, , wbemFlagForwardOnly Or wbemFlagReturnImmediately)

	' Get SMS_MonthlyUsageSummary
		' Build query to get all monthly summary information.
		monthlyUsageSummaryQuery = "SELECT * FROM SMS_MonthlyUsageSummary"
		' Run query.
		Set monthlyUsageSummaries = connection.ExecQuery(monthlyUsageSummaryQuery, , wbemFlagForwardOnly Or wbemFlagReturnImmediately)
	'Get SMS_MeteredUser
		' Build query to get all metered users.
		meteredUserQuery = "SELECT * FROM SMS_MeteredUser"
		' Run query.
		Set meteredUsers = connection.ExecQuery(meteredUserQuery, , wbemFlagForwardOnly Or wbemFlagReturnImmediately)

	'Get computer names 
		' Build query to get all metered computers.
		meteredComputerQuery = "SELECT * FROM SMS_R_System"
		' Run query.
		Set meteredComputers = connection.ExecQuery(meteredComputerQuery, , wbemFlagForwardOnly Or wbemFlagReturnImmediately)

	For Each summary in monthlyUsageSummaries

		For each meteredFile in meteredFiles
			if meteredFile.MeteredFileID=summary.FileID then
				wscript.echo "File Name:" & meteredFile.FileName
				Exit For 
			end if
		for each meteredUser in meteredUsers
			if meteredUser.MeteredUserID=summary.MeteredUserID then
				wscript.echo "User Name: " & meteredUser.FullName
				Exit For
			end if
		wscript.echo "Usage Count:" & summary.UsageCount
		wscript.echo "Terminal Service Usage Count:" & summary.TSUsageCount
		for each computer in meteredComputers
			if computer.ResourceId=summary.ResourceID then
				wscript.echo "Computer:" & computer.Name
				Exit For
			end if


end sub
C#  Copy Code
public void ViewMonthlySummaryInfo(WqlConnectionManager connection)
		// Get SMS_MeteredFiles - used to match FileID to a file name.

			// Build query to get all metered files.
			string meteredFilesQuery = "SELECT * FROM SMS_MeteredFiles";

			// Run meteredFiles query.
			IResultObject meteredFiles = connection.QueryProcessor.ExecuteQuery(meteredFilesQuery);

		// Get SMS_MonthlyUsageSummary.

			// Build query to get all of the monthly file usage summary information.
			string monthlyUsageSummaryQuery = "SELECT * FROM SMS_MonthlyUsageSummary";

			// Run monthlyUsageSummaryQuery query.
			IResultObject monthlyUsageSummaries = connection.QueryProcessor.ExecuteQuery(monthlyUsageSummaryQuery);

		// Get SMS_MeteredUsers.
			// Build query to get all of the metered users.
			string meteredUserQuery = "SELECT * FROM SMS_MeteredUser";

			// Run meteredUser query.
			IResultObject meteredUsers = connection.QueryProcessor.ExecuteQuery(meteredUserQuery);

		// Get computer names.

			// Build query to get all the metered computers.
			string meteredComputersQuery = "SELECT * FROM SMS_R_System";

			// Run fileUsageSummary query.
			IResultObject meteredComputers = connection.QueryProcessor.ExecuteQuery(meteredComputersQuery);
		// Enumerate through the lists, outputs results as matches are found.
		foreach (IResultObject summary in monthlyUsageSummaries)
			foreach (IResultObject meteredFile in meteredFiles)
				if (meteredFile["MeteredFileID"].StringValue == summary["FileID"].StringValue)
					Console.WriteLine("File Name: " + meteredFile["FileName"].StringValue);

			foreach(IResultObject meteredUser in meteredUsers)
				if (meteredUser["MeteredUserID"].StringValue == summary["MeteredUserID"].StringValue)
					Console.WriteLine("User Name: " + meteredUser["FullName"].StringValue);

			Console.WriteLine("Usage Count: " + summary["UsageCount"].StringValue);
			Console.WriteLine("Terminal Service Usage Count: " + summary["TSUsageCount"].StringValue);

			foreach(IResultObject computer in meteredComputers)
				if(computer["ResourceId"].StringValue == summary["ResourceID"].StringValue)
					Console.WriteLine("Computer: " + computer["Name"].StringValue);

			Console.WriteLine(" ");

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

The example method has the following parameters:





  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

Compiling the Code

This C# example requires:










Robust Programming

For more information about error handling, see About Configuration Manager Errors.


For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.

See Also

Send comments about this topic to Microsoft.