You track System Center 2012 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
-
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
-
Get an instance of SMS_StateMigration.
-
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 |
|
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 Securing Configuration Manager Applications.
See Also
Tasks
How to Connect to an SMS Provider in Configuration Manager by Using Managed CodeHow to Connect to an SMS Provider in Configuration Manager by Using WMI
Concepts
Configuration Manager Operating System DeploymentConfiguration Manager Objects
Configuration Manager Programming Fundamentals
Operating System Deployment Computer Management