排除檔案和設定

當移 轉.xml 檔案 MigApp.xmlMigDocs.xmlMigUser.xml 指定時,用戶狀態移轉工具 (USMT) 移轉所列的設定和元件,如 USMT 移轉什麼? 您可以建立自定義 .xml 檔,以進一步指定要在移轉中包含或排除的專案。 此外, Config.xml 也可以建立檔案,以從移轉中排除整個元件。 不過,無法使用移轉 .xml 檔案或 Config.xml 檔案來排除使用者。 指定要包含和排除哪些使用者的唯一方法,是在 ScanState 工具的命令行上使用用戶選項。 如需詳細資訊,請參閱 ScanState 語法一文的用戶選項一節。

自訂移轉及包含和排除檔案和設定的方法包括:

  • 建立自訂 .xml 檔。 下列元素可用來指定要排除的專案:

    • 包含和排除include<><exclude> 元素可用來排除具有條件的物件。 例如,您可以移轉磁碟驅動器中 C:\ 的所有檔案,但任何 .mp3 檔案除外。 請務必記住, 衝突和優先順序適用於 這些元素。

    • 無條件的Exclude:無 <條件Exclude> 元素可用來全域排除數據。 這個專案的優先順序高於 .xml 檔案中的所有其他包含和排除規則。 因此,不論 .xml檔案中的任何其他<包含>規則為何,這個專案都會排除 物件。 例如,您可以在計算機上排除所有 .mp3 檔案,或排除 C:\UserData 中的所有檔案。

  • 建立 Config.xml 檔案Config.xml 可以建立和修改檔案,以從移轉中排除整個元件。 例如,此檔案可用來排除其中一個默認應用程式的設定。 此外,建立和修改檔案是排除移轉至執行 Windows 之電腦之作業系統設定的唯一 Config.xml 方式。 排除使用此檔案的元件比修改移轉 .xml 檔案更容易,因為不需要熟悉移轉規則和語法。

建立自訂 .xml 檔

Microsoft 建議您建立自定義 .xml 檔案,而不是修改預設的移 轉.xml 檔案。 使用自定義 .xml 檔案時,變更可以與預設 .xml 檔案分開,讓您更輕鬆地追蹤修改。

<包含> 和 <排除>

轉.xml 檔案MigApp.xmlMigDocs.xmlMigUser.xml包含<元件>專案,通常代表獨立元件或應用程式,例如 Microsoft Office Outlook 和 Word。 若要排除與這些元件相關聯的檔案和登錄設定,請使用 include<><exclude> 元素。 例如,這些元素可用來移轉模式 X 的所有檔案和設定,但模式 Y 的檔案和設定除外,其中 Y 比 X 更明確。如需這些元素的語法,請參閱 USMT XML 參考

注意

如果指定了排除>規則,請一律指定對應的 include 規則。<>< 否則,如果 <未指定 include> 規則,則不會包含特定檔案或設定。 它們已從移轉中排除。 因此,不需要未撰寫排除<>規則。

範例 1:如何移 C:\ 轉檔案以外的 .mp3 所有檔案

下列 .xml 檔案會移轉位於 C: 磁碟驅動器上的所有檔案,但任何 .mp3 檔案除外。

<migration urlid="http://www.microsoft.com/migration/1.0/migxmlext/mp3files">
    <!-- This component migrates all files except those with .mp3 extension-->
    <component type="Documents" context="UserAndSystem">
        <displayName _locID="miguser.sharedvideo">MP3 Files</displayName>
        <role role="Data">
            <rules>
                <include filter='MigXmlHelper.IgnoreIrrelevantLinks()'>
                    <objectSet>
                        <pattern type="File">C:\* [*]</pattern>
                    </objectSet>
                </include>
                <exclude>
                    <objectSet>
                        <pattern type="File">C:\* [*.mp3]</pattern>
                    </objectSet>
                </exclude>
            </rules>
        </role>
    </component>
</migration>

範例 2:如何移轉 中 C:\Data 除了檔案以外的所有檔案 C:\Data\tmp

下列 .xml 檔案會移轉 中 C:\Data的所有檔案和子資料夾,但中的 C:\Data\tmp檔案和子資料夾除外。

<migration urlid="http://www.microsoft.com/migration/1.0/migxmlext/test">
    <component type="Documents" context="System">
        <displayName _locID="miguser.sharedvideo">Test component</displayName>
        <role role="Data">
            <rules>
                <include>
                    <objectSet>
                        <pattern type="File">C:\Data\* [*]</pattern>
                    </objectSet>
                </include>
                <exclude>
                    <objectSet>
                        <pattern type="File"> C:\Data\temp\* [*]</pattern>
                    </objectSet>
                </exclude>
            </rules>
        </role>
    </component>
</migration>

範例 3:如何排除資料夾中的檔案,但包含所有子資料夾

下列 .xml 檔案會移轉 中 C:\EngineeringDrafts的任何子資料夾,但排除 中 C:\EngineeringDrafts的所有檔案。

<migration urlid="http://www.microsoft.com/migration/1.0/migxmlext/test">
    <component type="Documents" context="System">
        <displayName>Component to migrate all Engineering Drafts Documents without subfolders</displayName>
        <role role="Data">
            <rules>
                <include>
                    <objectSet>
                        <pattern type="File"> C:\EngineeringDrafts\* [*]</pattern>
                    </objectSet>
                </include>
                <exclude>
                    <objectSet>
                        <pattern type="File"> C:\EngineeringDrafts\ [*]</pattern>
                    </objectSet>
                </exclude>
            </rules>
        </role>
    </component>
</migration>

範例 4:如何從特定資料夾中排除檔案

下列 .xml 檔案會移轉 中C:\EngineeringDrafts的所有檔案和子資料夾,但中的C:\EngineeringDrafts檔案除外Sample.doc

<migration urlid="http://www.microsoft.com/migration/1.0/migxmlext/test">
    <component type="Documents" context="System">
        <displayName>Component to migrate all Engineering Drafts Documents except Sample.doc</displayName>
        <role role="Data">
            <rules>
                <include>
                    <objectSet>
                        <pattern type="File"> C:\EngineeringDrafts\* [*]</pattern>
                    </objectSet>
                </include>
                <exclude>
                    <objectSet>
                        <pattern type="File"> C:\EngineeringDrafts\ [Sample.doc]</pattern>
                    </objectSet>
                </exclude>
            </rules>
        </role>
    </component>
</migration>

範例 5:如何從任何位置排除檔案

若要從 C: 磁碟驅動器上的任何位置排除 Sample.doc 檔案,請使用 <pattern> 元素。 如果 C: 磁碟驅動器上有多個具有相同名稱的檔案,則會排除所有這些檔案。

<pattern type="File"> C:\* [Sample.doc] </pattern>

若要從電腦上的任何磁碟驅動器排除 Sample.doc 檔案,請使用 <script> 元素。 如果存在多個具有相同名稱的檔案,則會排除所有這些檔案。

<script>MigXmlHelper.GenerateDrivePatterns("* [sample.doc]", "Fixed")</script>

如何使用 XML 來排除檔案、資料夾和登錄機碼的範例

以下是一些如何使用 XML 來排除檔案、資料夾和登錄機碼的範例。 如需詳細資訊,請參閱 USMT XML 參考

範例 1:如何排除所有 .mp3 檔案

下列 .xml 檔案會從移轉中排除所有 .mp3 檔案:

<migration urlid="http://www.microsoft.com/migration/1.0/migxmlext/excludefiles">
    <component context="System" type="Documents">
        <displayName>Test</displayName>
        <role role="Data">
            <rules>
                <unconditionalExclude>
                    <objectSet>
                        <script>MigXmlHelper.GenerateDrivePatterns ("* [*.mp3]", "Fixed")</script>
                    </objectSet>
                </unconditionalExclude>
            </rules>
        </role>
    </component>
</migration>
範例 2:如何排除特定磁碟驅動器上的所有檔案

下列 .xml 檔案只會排除位於 C: 磁碟驅動器上的檔案。

<migration urlid="http://www.microsoft.com/migration/1.0/migxmlext/allfiles">
    <component type="Documents" context="System">
        <displayName>Test</displayName>
        <role role="Data">
            <rules>
                <unconditionalExclude>
                    <objectSet>
                        <pattern type="File">c:\*[*]</pattern>
                    </objectSet>
                </unconditionalExclude>
            </rules>
        </role>
    </component>
</migration>
範例 3:如何排除登錄機碼

下列 .xml 檔案會無條件地排除 HKEY_CURRENT_USER 登錄機碼及其所有子機碼。

<?xml version="1.0" encoding="UTF-8"?>
<migration urlid="http://www.microsoft.com/migration/1.0/migxmlext/miguser">
    <component type="Documents" context="User">
        <displayName>Test</displayName>
        <role role="Data">
            <rules>
                <include>
                    <objectSet>
                        <pattern type="Registry">HKCU\testReg[*]</pattern>
                    </objectSet>
                </include>
                <unconditionalExclude>
                    <objectSet>
                        <pattern type="Registry">HKCU\*[*]</pattern>
                    </objectSet>
                </unconditionalExclude>
            </rules>
        </role>
    </component>
</migration>
範例 4:如何排除 C:\WindowsC:\Program Files

下列 .xml 檔案會無條件地排除 和C:\Program FilesC:\Windows系統資料夾。 所有 *.docx*.xls*.ppt 檔案都未移轉, <因為無條件Exclude> 元素優先於 <include> 元素。

<?xml version="1.0" encoding="UTF-8"?>
<migration urlid="http://www.microsoft.com/migration/1.0/migxmlext/miguser">
    <component type="Documents" context="System">
        <displayName>Test</displayName>
        <role role="Data">
            <rules>
                <include>
                    <objectSet>
                        <script>MigXmlHelper.GenerateDrivePatterns ("* [*.doc]", "Fixed")</script>
                        <script>MigXmlHelper.GenerateDrivePatterns ("* [*.xls]", "Fixed")</script>
                        <script>MigXmlHelper.GenerateDrivePatterns ("* [*.ppt]", "Fixed")</script>
                    </objectSet>
                </include>
                <unconditionalExclude>
                    <objectSet>
                        <pattern type="File">C:\Program Files\* [*]</pattern>
                        <pattern type="File">C:\Windows\* [*]</pattern>
                    </objectSet>
                </unconditionalExclude>
            </rules>
        </role>
    </component>
</migration>

建立組態 XML 檔案

Config.xml您可以建立和修改檔案,以從移轉中排除元件。 排除使用此檔案的元件比修改移轉 .xml 檔案更容易,因為不需要熟悉移轉規則和語法。 Config.xml 是選擇性檔案,可使用 /genconfig 命令行選項搭配 ScanState 工具來建立。 例如, Config.xml 檔案可用來排除其中一個默認應用程式的設定。 此外,建立和修改此檔案是排除移轉至執行 Windows 之電腦之作業系統設定的唯一方式。

  • 若要排除預設應用程式的設定:migrate="no"檔案的 [應用程式>] 區段下<指定應用程式。Config.xml

  • 若要排除操作系統設定:針對 migrate="no"[WindowsComponents>] 區段下的<設定指定 。

  • 若要排除 Documents 資料夾: 指定 migrate="no" [ 檔案 ] 區段下的 <[檔案] 檔案> 夾。 仍會套用 .xml 檔案中的任何<包含>規則。 例如,如果規則包含 Documents 資料夾中的所有 .docx 檔案,則仍會移轉.docx檔案。 不過,不會移轉任何未 .docx 的額外檔案。

如需詳細資訊, 請參閱Config.xml 檔案]

注意

若要從檔案中Config.xml排除元件,請將移轉值設定為 “no”。 從檔案中刪除元件的 Config.xml XML 標籤,並不會從移轉中排除元件。