共用方式為


如何設定狀態移轉點的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;  
    }  
}  

範例方法具有下列參數:

參數 Type 描述
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
設定僅限還原模式。

- Managed: true 開啟僅限還原模式,否則 false 為 。
- VBScript: 1 開啟還原模式,否則 0 為 。

正在編譯程式碼

C# 範例具有下列編譯需求:

命名空間

系統

System.Collections.Generic

System.Text

Microsoft。ConfigurationManagement.ManagementProvider

Microsoft。ConfigurationManagement.ManagementProvider.WqlQueryEngine

組件

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

健全的程式設計

如需錯誤處理的詳細資訊,請參閱關於Configuration Manager錯誤

.NET Framework 安全性

如需保護Configuration Manager應用程式的詳細資訊,請參閱Configuration Manager角色型系統管理

另請參閱

關於 OS 部署月臺角色設定如何使用 Managed 程式碼讀取和寫入Configuration Manager月臺控制檔案
如何使用 WMI 讀取和寫入Configuration Manager月臺控制檔案