You track Microsoft System Center Configuration Manager 2007 operating system migrations by inspecting the SMS_StateMigration Server WMI Class class.

The StoreCreationDate, StoreDeletionDate, and StoreReleaseDate properties can be used to identify the current state of the migration.

To track state migrations

  1. Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

  2. Get an instance of SMS_StateMigration.

  3. Calculate the current migration state using the StoreCreationDate, StoreDeletionDate, and StoreReleaseDate properties.

Example

The following example method enumerates through all migrations and determines whether they are in progress.

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

Visual Basic Script  Copy Code
Sub MigrationState(connection)

	Dim migrations
	Dim migration
	Dim inProgress
	Dim zeroTime
	
	zeroTime = "00000000000000.000000+***"

	Set migrations = connection.ExecQuery( "Select * From SMS_StateMigration")

	For Each migration in Migrations
		inProgress=False
			
		If migration.StoreCreationDate<>zeroTime Then
			If migration.StoreReleaseDate = zeroTime Then
				inProgress=True
			Else If migration.StoreDeletionDate = zeroTime Then
				inProgress = True
			Else
				inProgress = false
			End If
		End If   
		Else
			inProgress=False
		End If
		 
		WScript.StdOut.Write "Migration " + migration.MigrationID
		If inProgress = True Then
			Wscript.Echo " is in progress"
		Else
			WScript.Echo " is not in progress"
		End If   
	Next

End Sub   
C#  Copy Code
public void MigrationState(WqlConnectionManager connection)
{
	try
	{
		IResultObject migrations =
			connection.QueryProcessor.ExecuteQuery("Select * from SMS_StateMigration");

		string zeroTime = "00000000000000.000000+***";

		foreach (IResultObject migration in migrations)
		{
			Boolean inProgress = false;
		

			if (migration["StoreCreationDate"].DateTimeValue.Equals(zeroTime) == false)
			{
				if (migration["StoreReleaseDate"].DateTimeValue.Equals(zeroTime) == true)
				{
					inProgress = true;
			}
				else if (migration["StoreDeletionDate"].DateTimeValue.Equals(zeroTime) == true)
				{
					inProgress = true;
			}
				else
				{
					inProgress = false;
			}
		}
			else
			{
				inProgress = false;
		}

			Console.Write("Migration " + migration["MigrationID"].StringValue);
			if (inProgress)
			{
				Console.WriteLine(" is in progress");
		}
			else
			{
				Console.WriteLine(" is not in progress");
		}
	}
}
	catch (SmsException e)
	{
		Console.WriteLine("Failed while displaying migration state: " + e.Message);
		throw;
}
}

The example method has the following parameters:

Parameter

Type

Description

connection

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

Compiling the Code

The C# example has the following compilation requirements:

Namespaces

System

System.Collections.Generic

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

Robust Programming

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

Security

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

See Also


Send comments about this topic to Microsoft.