排除文件和设置

当迁移 .xml 文件 MigApp.xmlMigDocs.xmlMigUser.xml 指定后,用户状态迁移工具 (USMT) 迁移列出的设置和组件,如 USMT 迁移的内容中所述。 可以创建自定义 .xml 文件,以进一步指定要在迁移中包括或排除的内容。 此外,还可以创建一个 Config.xml 文件,从迁移中排除整个组件。 但是,无法使用迁移 .xml 文件或 Config.xml 文件来排除用户。 指定要包含和排除的用户的唯一方法是使用 ScanState 工具的命令行上的用户选项。 有关详细信息,请参阅 ScanState 语法一文的用户选项部分。

自定义迁移以及包括和排除文件和设置的方法包括:

  • 创建自定义 .xml 文件。 以下元素可用于指定要排除的内容:

    • 包含和排除include<><exclude> 元素可用于排除具有条件的对象。 例如,可以迁移驱动器中的所有 C:\ 文件,但任何 .mp3 文件除外。 请务必记住 ,冲突和优先级 适用于这些元素。

    • unconditionalExclude无<条件Exclude> 元素可用于全局排除数据。 此元素优先于 .xml 文件中的所有其他包含和排除规则。 因此,无论 .xml 文件中的任何其他 <include> 规则,此元素都会排除对象。 例如,可以在计算机上排除所有 .mp3 文件,也可以排除 C:\UserData 中的所有文件。

  • 创建 Config.xml 文件Config.xml 可以创建和修改文件,以从迁移中排除整个组件。 例如,此文件可用于排除其中一个默认应用程序的设置。 此外,创建和修改 Config.xml 文件是排除迁移到运行 Windows 的计算机的操作系统设置的唯一方法。 使用此文件排除组件比修改迁移 .xml 文件更容易,因为不需要熟悉迁移规则和语法。

创建自定义 .xml 文件

Microsoft 建议创建自定义 .xml 文件,而不是修改默认迁移 .xml 文件。 使用自定义 .xml 文件时,更改可以独立于默认 .xml 文件,从而更轻松地跟踪修改。

<include> 和 <exclude>

迁移 .xml 文件 MigApp.xmlMigDocs.xmlMigUser.xml包含<组件>元素,该元素通常表示自包含组件或应用程序(如 Microsoft Office Outlook 和 Word)。 若要排除与这些组件关联的文件和注册表设置,请使用 <include><exclude> 元素。 例如,这些元素可用于迁移具有模式 X 的所有文件和设置,但模式为 Y 的文件和设置除外,其中 Y 比 X 更具体。有关这些元素的语法,请参阅 USMT XML 参考

注意

如果指定了排除>规则,请始终指定相应的包含规则。<<> 否则,如果未 <指定包含> 规则,则不包含特定文件或设置。 它们已从迁移中排除。 因此,不需要无人陪伴的 <排除> 规则。

示例 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 Files的系统C:\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>

创建 Config XML 文件

Config.xml可以创建和修改文件,以便从迁移中排除组件。 使用此文件排除组件比修改迁移 .xml 文件更容易,因为不需要熟悉迁移规则和语法。 Config.xml是一个可选文件,可以使用命令行选项和 ScanState 工具创建/genconfig该文件。 例如, Config.xml 该文件可用于排除其中一个默认应用程序的设置。 此外,创建和修改此文件是排除迁移到运行 Windows 的计算机的操作系统设置的唯一方法。

  • 若要排除默认应用程序的设置,请执行以下操作:在文件的“应用程序>”部分下<为应用程序指定 migrate="no"Config.xml

  • 排除操作系统设置:WindowsComponents> 部分下的<设置指定migrate="no"

  • 若要排除 Documents 文件夹,请执行以下命令:“文档”部分下的<“文档”>文件夹指定 migrate="no" 。 仍会应用 .xml 文件中的任何<包含>规则。 例如,如果存在包含 Documents 文件夹中所有 .docx 文件的规则,则仍会迁移 .docx 文件。 但是,不会迁移未 .docx 的任何其他文件。

有关详细信息,请参阅 Config.xml 文件

注意

若要从Config.xml文件中排除组件,请将迁移值设置为“no”。Config.xml 文件中删除组件的 XML 标记不会从迁移中排除组件。