How to Track Operating System Deployment Migrations in Configuration Manager

 

Updated: November 1, 2013

Applies To: System Center 2012 Configuration Manager, System Center 2012 Configuration Manager SP1, System Center 2012 R2 Configuration Manager

You track System Center 2012 R2 Configuration Manager 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.

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   
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:

System

System.Collections.Generic

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

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.

Show: