USMT 基本上只是一个备份工具吗?

USMT 基本上只是一个备份工具吗?

我对此的理解正确吗?

USMT 将用户数据、设置等复制到网络驱动器,然后安装操作系统,然后再次使用 USMT 将文件、设置等复制回来。

答案1

如果您想要简短、简单、精简的版本,USMT 确实“只是”一个备份工具。我对它还不太熟悉,但编写脚本后,它可以成为管理员的一个有用工具。希望这对您有所帮助!

以下是一个批处理文件,可自动执行 USMT 的加载状态部分。我没有为 array_compare.ps1 编写代码,但如果有人真的感兴趣,我可以发布它。玩得开心,如果您有任何问题请告诉我!

检查脚本是否在提升状态下运行,若否,则提升自身。

:::::::::::::::::::::::::::::::::::::::::
::
:: Automatically check & get admin rights
:::::::::::::::::::::::::::::::::::::::::
@echo off
CLS 
ECHO.
ECHO =============================
ECHO Running Admin shell
ECHO =============================
: checkPrivileges 
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )  
:getPrivileges 
if '%1'=='ELEV' 
(shift & goto gotPrivileges)  
ECHO. 
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation 
ECHO ************************************** 
setlocal DisableDelayedExpansion
set "batchPath=%~0"
setlocal EnableDelayedExpansion
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs" 
ECHO UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs" 
"%temp%\OEgetPrivileges.vbs" 
exit /B  
:gotPrivileges 
::::::::::::::::::::::::::::
::START::::::::::::::::::::::::::::
setlocal & pushd . 

REM Run shell as admin (example)
:::::::::::::::::::::::::::: 

映射我用来存储和维护所需杂项文件的网络驱动器。它还存储了稍后要加载的 USMT 文件。

@ECHO OFF
START /wait NET USE z: \\NETWORK SHARE\FOLDER\FOLDER
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Lines 42 - 44 Run the array_compare.ps1 as Admin      ::
:: to run a search to find the new user name and output  ::
:: it to a file that we will read from shortly.          ::
:: THIS CAN BE PROVIDED...LET ME KNOW!!                  ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

array_compare.ps1 获取两个用户名列表并进行比较,然后将其输出到将被读取以导入配置文件的 csv 文件。

SET ThisScriptsDirectory=%~dp0 
SET PowerShellScriptPath="Z:\Path\to\powershell\comparison\array_compare.ps1"
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '->NoProfile -ExecutionPolicy Bypass -File ""%PowerShellScriptPath%""' -Verb RunAs}";

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::  Change the Powershell ExecutionPolicy so that scripts will run without issue. ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

PowerShell -NoProfile -ExecutionPolicy Unrestricted -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Unrestricted'}"

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::      ***Declaring our variables***               ::
:: Location is the folder name where we stored the scanstate information.  ::
:: Domain2 is the new domain that we are migrating to.                     ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Scanstate 将文件保存在网络共享中以主机命名的文件夹中。这里我们被提示输入要更换的设备的主机名。

set /P location= Please enter the OLD computer name:

由于 USMT 有两个基于操作系统位级别的不同 .exe,Win 7x86 与 Win 7x64,所以我想运行检查并在此基础上执行正确的加载状态。

询问处理器以确定架构类型。

:CheckOS

   if /i %processor_architecture%==AMD64 GOTO AMD64
Else    
if /i %processor_architecture%==x86 GOTO x86
Else
if /i %PROCESSOR_ARCHITEW6432%==AMD64 GOTO AMD64

 :AMD64
Z:
CD Z:\Program Files\USMT\x64\
xcopy *.* /e /v /y c:\windows\usmt\

C:
CD c:\windows\usmt\

setlocal EnableDelayedExpansion



Set inputfile=Z:\%location%\NAME_OF_FILE_THAT_CONTAINS_BOTH_USERIDS.txt

for /f "tokens=1-2" %%A in (%inputfile%) do call :USMTx64 %%A%%B

:USMTx64
ECHO Syncing %1 ...
loadstate Z:\%location% /c /lac /lae /i:miguser.xml /i:migapp.xml /i:novell_excl.xml /config:config.xml /ue:Administrator /ue:Admin* /ue:EO-* /ue:*\* /ui:%1 /mu:<OLDDOMAIN>\%1:ID\%2 /mu:%1:ID\%2 /v:13 

if NOT ["%errorlevel%"]==["0"] (
    GOTO END        
    )
exit /b

:x86
Z:
CD Z:\Program Files\USMT\x86
xcopy *.* /e /v /y c:\windows\usmt\

C:
CD c:\windows\usmt\

Set inputfile=Z:\%location%\NAME_OF_FILE_THAT_CONTAINS_BOTH_USERIDS.txt

创建了一个 for /f 循环,用于读取先前的 array_compare.ps1 中的输出文件。这才是真正为我们自动化 USMT 的方法。它将执行 X 次,每次加载一个新用户。

for /f "tokens=1-2" %%A in (%inputfile%) do call :USMTx86 %%A%%B
:USMTx86
ECHO Syncing %1 ...
loadstate Z:\%location% /c /lac /lae /i:miguser.xml /i:migapp.xml /i:novell_excl.xml /config:config.xml /ue:Administrator /ue:EO-* /ue:Admin* /ui:%1 /ue:*\* /mu:<OLDDOMAIN>\%1:ID\%2 /mu:%1:ID\%2 /v:13 

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::    :::::::::::: 
:: Checks for errors in the USMT commands.  
:: If found exits the CALL sub and continues with the script.
::::  SOURCE: https://coderwall.com/p/jexjlw
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

这个错误循环是绝对必要的,至少对我来说是这样!当 for /f 进行到最后一次迭代时,USMT 将出错。如果发生这种情况并且仍有命令要运行,则批处理文件将失败。这将处理它,退出 for /f 循环并继续。

if NOT ["%errorlevel%"]==["0"] (
    GOTO END
    )
exit /b

:END

:: Deletes the mapped network drive

net use z: /delete /yes

Exit

相关内容