如何为状态迁移点设置 Restore-Only 模式

在 Configuration Manager 中,通过设置 SMPQuiesceState 嵌入属性,将作系统部署状态迁移点配置为拒绝存储用户数据的新请求。

SMPQuiesceState 有两个可能的值。

定义
0 仅还原模式已关闭。
1 仅还原模式已打开。

为状态迁移点设置仅还原模式

  1. 设置与 SMS 提供程序的连接。 有关详细信息,请参阅 SMS 提供程序基础知识

  2. 与站点控制文件的状态迁移点资源部分建立连接。

  3. 获取嵌入的属性。

  4. 更新 SMPQuiesceState

  5. 提交对站点控制文件的更改。

示例

以下示例方法基于提供的值设置仅还原模式。

有关调用示例代码的信息,请参阅调用Configuration Manager代码片段

Sub SetRestoreOnlyMode(connection,          _
                       context,           _
                       siteCode,               _
                       enableRestoreOnlyMode)

    ' Load site control file and get SMS State Migration Point section.
    connection.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Refresh", , , context

    Query = "SELECT * FROM SMS_SCI_SysResUse " & _
            "WHERE RoleName = 'SMS State Migration Point' " & _
            "AND SiteCode = '" & siteCode & "'"

    Set SCIComponentSet = connection.ExecQuery(Query, , , context)

    ' Only one instance is returned from the query.
    For Each SCIComponent In SCIComponentSet

         ' Display state migration point server name.
         wscript.echo "SMS State Migration Point Server: " & SCIComponent.NetworkOSPath

        ' Loop through the array of embedded property instances.
        For Each vProperty In SCIComponent.Props

            ' Setting: SMPQuiesceState
            If vProperty.PropertyName = "SMPQuiesceState" Then
                wscript.echo " "
                wscript.echo vProperty.PropertyName
                wscript.echo "Current value " &  vProperty.Value

                ' Modify the value.
                vProperty.Value = enableRestoreOnlyMode
                wscript.echo "New value " & enableRestoreOnlyMode
            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_( , context)
    Next

    ' Commit the change to the actual site control file.
    Set InParams = connection.Get("SMS_SiteControlFile").Methods_("CommitSCF").InParameters.SpawnInstance_
    InParams.SiteCode = siteCode
    connection.ExecMethod "SMS_SiteControlFile", "CommitSCF", InParams, , context
End Sub
public void SetRestoreOnlyMode(
    WqlConnectionManager connection,
    string server,
    string siteCode,
    bool enableRestoreOnlyMode)
{
    try
    {
        // Get the site control file.
        IResultObject ro = connection.GetInstance("SMS_SCI_SysResUse.FileType=2,ItemName='[\"Display=\\\\" + server + "\\\"]MSWNET:[\"SMS_SITE=" + siteCode + "\"]\\\\" + server + "\\,SMS State Migration Point',ItemType='System Resource Usage',SiteCode='" + siteCode + "'");

        // Get the embedded properties.
        Dictionary<string, IResultObject> embeddedProperties = ro.EmbeddedProperties;

        // Set the restore only mode.
        embeddedProperties["SMPQuiesceState"]["Value"].BooleanValue = enableRestoreOnlyMode;

        ro.EmbeddedProperties = embeddedProperties;

        // Commmit the changes.
        ro.Put();
    }
    catch (SmsException e)
    {
        Console.WriteLine("Failed to set restore only mode" + e.Message);
        throw;
    }
}

示例方法具有以下参数:

参数 类型 说明
connection -管理: WqlConnectionManager
- VBScript: SWbemServices
与 SMS 提供程序的有效连接。
context (VBScript) - VBScript: SWbemContext 有效的上下文对象。 有关详细信息,请参阅如何使用 WMI 添加Configuration Manager上下文限定符
server -管理: String
- VBScript: String
运行状态迁移点的Configuration Manager服务器。
siteCode -管理: String
- VBScript: String
Configuration Manager站点代码。
enableRestoreOnlyMode -管理: Boolean
- VBScript: Integer
设置仅还原模式。

- 托管: true 打开“仅还原”模式;否则为 false
- VBScript: 1 打开还原模式;否则为 0

编译代码

C# 示例具有以下编译要求:

命名空间

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

可靠编程

有关错误处理的详细信息,请参阅关于Configuration Manager错误

.NET Framework 安全性

有关保护Configuration Manager应用程序的详细信息,请参阅Configuration Manager基于角色的管理

另请参阅

关于 OS 部署站点角色配置如何使用托管代码读取和写入Configuration Manager站点控制文件 如何使用 WMI 读取和写入Configuration Manager站点控制文件