我实际上只是做了同样的事情!好的,所以我放在一起的以下“代码”是批量的,因为它既简单又轻巧。它不漂亮,但它完成了工作。
它的步骤:
- 连接到机器和用户配置文件。如果机器离线,它会告诉你。如果提供的用户名与配置文件不匹配,它将返回计算机上的配置文件列表,以便您可以将呼叫者与正确的配置文件匹配。
- 将 EFS 证书备份到桌面。
- 网络驱动器和打印机备份到用户桌面上的文本文件。
- 用户自动注销
- 将“old_”附加到本地配置文件名称的开头,并将重建的日期和时间附加到末尾。
- 配置文件注册表项的备份导出了旧配置文件的“联系人”文件夹,然后将其从配置单元中删除。
- 将“配置文件迁移工具”复制到用户的桌面。这会将所有数据从旧配置文件移动到重建的配置文件。它还复制在 Fix Pack 中找到的“映射所有 PST 文件.vbs”文件。迁移所有数据后自动启动“映射所有 PST 文件.vbs”文件
- 完成所有步骤后,Outlook 将启动
第 1 步:您需要备份他们的数据,所以就是这样。将其另存为 Backup.bat
@title Profile Data Backup Tool v1.53
@echo off
echo.
echo.
if exist %USERPROFILE%\desktop\EFSCertBackup.cer del %USERPROFILE%\desktop\EFSCertBackup.cer
>goto :deletePFXFile
:deletePFXFile
if exist %USERPROFILE%\desktop\EFSCertBackup.pfx del %USERPROFILE%\desktop\EFSCertBackup.pfx
goto :backupefscerts
echo.
:backupefscerts
REM back up EFS Certs
echo This is a password you will create. If you do not want to create a password, press 'Enter' twice.
echo.
cipher /r:%USERPROFILE%\desktop\EFSCertBackup
REM back up network drives
net use > %USERPROFILE%\Desktop\NetworkDrivesandPrinters.txt
REM back up network printers
Cscript %WINDIR%\System32\Printing_Admin_Scripts\en-US\Prnmngr.vbs -l >> %USERPROFILE%\Desktop\NetworkDrivesandPrinters.txt
REM backup the registry key
set THEME_REGKEY="HKLM\SOFTWARE\Wow6432Node\Network Associates\ePolicy Orchestrator\Agent"
set THEME_REGVAL=LoggedOnUser
REM Check for presence of key first.
reg query %THEME_REGKEY% /v %THEME_REGVAL% || (echo No theme name present! & pause & exit /b 1)
REM query the value. pipe it through findstr in order to find the matching line that has the value. only grab token 3 and the remainder of the line. %%b is what we are interested in here.
set THEME_NAME=
for /f "tokens=2,*" %%a in ('reg query %THEME_REGKEY% /v %THEME_REGVAL% ^| findstr %THEME_REGVAL%') do (
set THEME_NAME=%%b
)
REM replace any spaces with +
set THEME_NAME=%THEME_NAME: =+%
echo.
echo Please wait. This window will close automatically once the tool is done running.
echo Please inform the agent once this window closes.
wmic useraccount where (name='%THEME_NAME%') get sid >SID.txt
powershell -Command "(gc SID.txt) -replace 'SID', '' | Out-File SID.txt"
powershell -Command "(gc SID.txt) -replace ' ', '' | Out-File SID.txt"
powershell -Command "(gc SID.txt) | ? {$_.trim() -ne '' } | set-content SID.txt"
for /f "delims=" %%x in (SID.txt) do set SID=%%x
reg export "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%SID%" "%Userprofile%\contacts\oldprofileBackupKey.reg"
shutdown.exe /l /f
(goto) 2>nul & del "%~f0"
2. 这将映射用户拥有的所有 PST 文件。将其另存为“映射所有 PST Files.vbs”
On error resume next
Dim objFSO
Dim objWSH
Dim objWMIService
Dim colProcess
Dim objProcess
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWSH = CreateObject("Wscript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Dim strUserProfile
Dim OutlookOpen
strUserProfile = objWSH.ExpandEnvironmentStrings("%USERPROFILE%")
objWSH.Run "%COMSPEC% /c DIR " & CHR(34) & strUserProfile & "\*.pst" & CHR(34) & " /b /s>" & CHR(34) & strUserProfile & "\My Documents\PST Locations.txt""", 0, True
objWSH.Run "%COMSPEC% /c DIR H:\*.pst /b /s>>" & CHR(34) & strUserProfile & "\My Documents\PST Locations.txt""", 0, True
If Not objFSO.FileExists(strUserProfile & "\My Documents\PST Locations.txt") Then
Done()
End If
Dim AppOutlook, OutlookNS, Path, objfile, Line
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process")
For Each objProcess In colProcess
If objProcess.Name = "OUTLOOK.EXE" Then OutlookOpen = True
Next
Set AppOutlook = CreateObject("Outlook.Application")
If err.number <> 0 Then
Set AppOutlook = GetObject(,"Outlook.Application")
End If
Set OutlookNS = AppOutlook.GetNameSpace("MAPI")
Set objfile = objFSO.opentextfile(strUserProfile & "\My Documents\PST Locations.txt")
Do Until objfile.AtEndOfStream
Line=objfile.readline
If instr(Line, "No PST mappings found") Then
Done()
Else
OutlookNS.AddStore Line
End If
Loop
If Not OutlookOpen Then
AppOutlook.Session.Logoff
AppOutlook.Quit
End If
objfile.close
Set objfile = Nothing
Set AppOutlook = Nothing
Set OutlookNS = Nothing
Done()
Sub Done()
MSGBOX "Remapping of PST(s) is complete. Please ensure that your PST(s) have been remapped succesfully."
If Not OutlookOpen Then objWSH.Run "%COMSPEC% /c Start Outlook",0,False
objFSO.DeleteFile(strUserProfile & "\Desktop\Map All PST Files.vbs")
Wscript.Quit
End Sub
3. 这是将所有数据从旧配置文件移动到新配置文件的部分。将其另存为“配置文件迁移工具.bat”
@echo off
set THEME_REGKEY="HKLM\SOFTWARE\Wow6432Node\Network Associates\ePolicy Orchestrator\Agent"
set THEME_REGVAL=LoggedOnUser
cls
REM Check for presence of key first.
reg query %THEME_REGKEY% /v %THEME_REGVAL% || (echo No theme name present! & pause & exit /b 1)
cls
REM query the value. pipe it through findstr in order to find the matching line that has the value. only grab token 3 and the remainder of the line. %%b is what we are interested in here.
set THEME_NAME=
for /f "tokens=2,*" %%a in ('reg query %THEME_REGKEY% /v %THEME_REGVAL% ^| findstr %THEME_REGVAL%') do (
set THEME_NAME=%%b
)
cls
set /p content=<oldprofile.txt
robocopy "%content%\Contacts" "C:\Users\%THEME_NAME%\Contacts" /MIR /E /E /COPY:DAT /IS /XA:SHT /XF *.ini /R:2 /W:5
robocopy "%content%\Downloads" "C:\Users\%THEME_NAME%\Downloads" /MIR /E /COPY:DAT /XA:SHT /XF *.ini /R:2 /W:5
robocopy "%content%\Documents" "C:\Users\%THEME_NAME%\Documents" /MIR /E /COPY:DAT /IS /XA:SHT /XD "My Music" /XD "My Pictures" /XD "My Videos" /XF *.ini /R:2 /W:5
robocopy "%content%\Desktop" "C:\Users\%THEME_NAME%\Desktop" /MIR /E /COPY:DAT /IS /XA:SHT /XF *.ini /R:2 /W:5
robocopy "%content%\Favorites" "C:\Users\%THEME_NAME%\Favorites" /MIR /E /COPY:DAT /IS /XA:SHT /XF *.ini /R:2 /W:5
robocopy "%content%\Links" "C:\Users\%THEME_NAME%\Links" /MIR /E /COPY:DAT /IS /XA:SHT /XF *.ini /R:2 /W:5
robocopy "%content%\Music" "C:\Users\%THEME_NAME%\Music" /MIR /E /COPY:DAT /IS /XA:SHT /XF *.ini /R:2 /W:5
robocopy "%content%\Pictures" "C:\Users\%THEME_NAME%\Pictures" /MIR /E /COPY:DAT /IS /XA:SHT /XF *.ini /R:2 /W:5
robocopy "%content%\Videos" "C:\Users\%THEME_NAME%\Videos" /MIR /E /COPY:DAT /IS /XA:SHT /XF *.ini /R:2 /W:5
robocopy "%content%" "C:\Users\%THEME_NAME%\Documents" /COPY:DAT /IS /XD /XF ntuser.* /XF *.ini /R:2 /W:5
killtask /im outlook.exe
cd %currentuser%\Desktop
wscript "MAP ALL PST Files.vbs" //e:vbscript
del oldprofile.txt
del "%~f0"&exit
4. 这是圣杯。实际重建配置文件的部分。它必须以管理员身份运行。将其另存为 RAP.bat:
@title Rebuild a Profile Tool Version 3.0
@echo off
:beginning
set THEME_REGKEY="HKLM\SOFTWARE\Wow6432Node\Network Associates\ePolicy Orchestrator\Agent"
set THEME_REGVAL=LoggedOnUser
REM Check for presence of key first.
reg query %THEME_REGKEY% /v %THEME_REGVAL% || (echo No theme name present! & pause>nul & exit /b 1)
REM query the value. pipe it through findstr in order to find the matching line that has the value. only grab token 3 and the remainder of the line. %%b is what we are interested in here.
set THEME_NAME=
for /f "tokens=2,*" %%a in ('reg query %THEME_REGKEY% /v %THEME_REGVAL% ^| findstr %THEME_REGVAL%') do (
set THEME_NAME=%%b
)
set RAPPath="\\127.0.0.1\C$\Program Files\HDUTILS\RAP"
cls
:connectIn
set /p remotepc= Enter the remote computer name or IP address:
if exist \\%remotepc%\C$\Users\ goto :inputUsername
echo Instruct user to restart the machine and log in.
SET tmout=3
PING 1.2.1.2 -n 1 -w %tmout%000 > NUL
echo.
goto :connectIn
:inputUsername
set /p remoteuser= Enter remote user's username:
if exist \\%remotepc%\C$\Users\%remoteuser%\ goto :choice
echo Invalid username. Please verify the spelling and try again.
SET tmout=3
PING 1.2.1.2 -n 1 -w %tmout%000 > NUL
dir \\%remotepc%\C$\Users\
goto :inputUsername
echo.
:choice
echo.
FOR %%? IN (\\%remotepc%\C$\Users\%remoteuser%\NTUSER.DAT) DO (ECHO %remoteUser%'s %%~n?%%~x? file size is %%~z? bytes)
echo Profile corruption typically occurs around 5000000 bytes.
echo.
REM This user's NTUSER.DAT file is over by ___ bytes.
set /P continue=Do you want to continue rebuilding this profile?[Y/N]
if /I "%continue%" EQU "Y" goto :sendBackup
if /I "%continue%" EQU "y" goto :sendBackup
if /I "%continue%" EQU "N" goto :abandon
if /I "%continue%" EQU "n" goto :abandon
echo.
echo Error: Invalid Parameter. Please press either "y" or "n" to continue.
echo.
goto :choice
:abandon
cls
echo Standby. Restarting program...
SET tmout=3
PING 1.2.1.2 -n 1 -w %tmout%000 > NUL
goto :beginning
REM Copy over the EFS Cert backup file
:sendBackup
set remoteuserdesktop=\\%remotepc%\C$\Users\%remoteuser%\Desktop
robocopy %RAPPath%\ %remoteuserdesktop%\ Backup.bat
echo.
echo.
echo.
echo Instruct the user to run the file named Backup.bat on their desktop and
echo let you know when it finishes. When it is done running, the command window
echo will close and 3 files should have appeared on the Desktop. Tell them to
echo inform you when they see the Ctrl + Alt + Del screen.
echo.
echo.
echo.
:SIDexist
if exist \\%remotepc%\c$\users\%remoteuser%\Desktop\SID.txt goto :copySID
goto :SIDexist
:copySID
robocopy %remoteuserdesktop%\ %RAPPath%\ SID.txt
del %remoteuserdesktop%\SID.txt
echo Press any key to rename the profile...
echo.
echo.
pause>nul
:rename
Set CURRDATE=%TEMP%\CURRDATE.TMP
Set CURRTIME=%TEMP%\CURRTIME.TMP
DATE /T > %CURRDATE%
TIME /T > %CURRTIME%
Set PARSEARG="eol=; tokens=1,2,3,4* delims=/, "
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET YYYYMMDD=%%l%%k%%j
Set PARSEARG="eol=; tokens=1,2,3* delims=:, "
For /F %PARSEARG% %%i in (%CURRTIME%) Do Set HHMM=%%i%%j%%k
Echo RENAME \\%remotepc%\C$\Users\%remoteuser% old_%remoteuser%_%YYYYMMDD%%HHMM%
RENAME \\%remotepc%\C$\Users\%remoteuser% old_%remoteuser%_%YYYYMMDD%%HHMM%
set oldusername=old_%remoteuser%_%YYYYMMDD%%HHMM%
echo old_%remoteuser%_%YYYYMMDD%%HHMM% >oldprofile.txt
powershell -Command "(gc oldprofile.txt) -replace ' ', '' | Out-File oldprofile.txt"
powershell -Command "(gc oldprofile.txt) | ? {$_.trim() -ne '' } | set-content oldprofile.txt"
:choice2
if exist \\%remotepc%\C$\Users\old_%remoteuser%_%YYYYMMDD%%HHMM% goto :regKeyDelete
goto :uhoh
:uhoh
echo Inform the user you will restart their computer momentarily. Tell them to let
echo you know when they see the 'Ctrl + Alt + Del'screen.
echo Verify network connectivity with the ping that is now running.
shutdown /r /m \\%remotepc% /c "Computer will not rename profile. When prompted for a green shutdown, press no. Press OK to continue." /d p:0:0
start cmd.exe @cmd /k "ping -t %remotepc%"
echo.
echo Wait 60 seconds after the machine comes back online, then press any key to
echo continue the rebuild...
pause>nul
goto :rename2
:rename2
Set CURRDATE=%TEMP%\CURRDATE.TMP
Set CURRTIME=%TEMP%\CURRTIME.TMP
DATE /T > %CURRDATE%
TIME /T > %CURRTIME%
Set PARSEARG="eol=; tokens=1,2,3,4* delims=/, "
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET YYYYMMDD=%%l%%k%%j
Set PARSEARG="eol=; tokens=1,2,3* delims=:, "
For /F %PARSEARG% %%i in (%CURRTIME%) Do Set HHMM=%%i%%j%%k
Echo RENAME \\%remotepc%\C$\Users\%remoteuser% old_%remoteuser%_%YYYYMMDD%%HHMM%
RENAME \\%remotepc%\C$\Users\%remoteuser% old_%remoteuser%_%YYYYMMDD%%HHMM%
set oldusername=old_%remoteuser%_%YYYYMMDD%%HHMM%
echo old_%remoteuser%_%YYYYMMDD%%HHMM% >oldprofile.txt
powershell -Command "(gc oldprofile.txt) -replace ' ', '' | Out-File oldprofile.txt"
powershell -Command "(gc oldprofile.txt) | ? {$_.trim() -ne '' } | set-content oldprofile.txt"
goto :choice3
:choice3
echo.
if exist \\%remotepc%\C$\Users\old_%remoteuser%_%YYYYMMDD%%HHMM% goto :regKeyDelete
goto :rename2
:regKeyDelete
REM Delete registry key
cd "C:\Program Files\HDUTILS\RAP\"
set /p Build=<SID.txt
reg delete "\\%remotepc%\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%Build%"
echo \\%remotepc%\C$\Users\old_%remoteuser%_%YYYYMMDD%%HHMM% >oldprofile.txt
echo.
echo.
echo Instruct the User to log in.
SET tmout=3
PING 1.2.1.2 -n 1 -w %tmout%000 > NUL
echo Waiting on customer login...
echo.
:listrebuilt
if exist \\%remotepc%\C$\Users\%remoteuser%\Desktop goto :nextplease
goto :listrebuilt
:nextplease
set remoteuserdesktop=\\%remotepc%\C$\Users\%remoteuser%
powershell -Command "(gc oldprofile.txt) -replace ' ', '' | Out-File oldprofile.txt"
powershell -Command "(gc oldprofile.txt) | ? {$_.trim() -ne '' } | set-content oldprofile.txt"
:copymigrationTools
robocopy %RAPPath%\ %remoteuserdesktop%\ oldprofile.txt
robocopy %RAPPath%\ %remoteuserdesktop%\ "Profile Migration Tool.bat"
robocopy %RAPPath%\ %remoteuserdesktop%\ "Map All PST files.vbs"
:checkFiles
if exist %remoteuserdesktop%\oldprofile.txt goto :checkPMT
goto :recopyProfile
:checkPMT
if exist "%remoteuserdesktop%\Profile Migration Tool.bat" goto :checkPST
goto :recopyPMT
:checkPST
if exist "%remoteuserdesktop%\Map All PST files.vbs" goto :finish
goto :recopyPST
:recopyProfile
robocopy %RAPPath%\ %remoteuserdesktop%\ oldprofile.txt
goto :checkFiles
:recopyPMT
robocopy %RAPPath%\ %remoteuserdesktop%\ "Profile Migration Tool.bat"
goto :checkFiles
:recopyPST
robocopy %RAPPath%\ %remoteuserdesktop%\ "Map All PST files.vbs"
goto :checkFiles
:finish
echo.
echo You have completed your end of the rebuild. MSRA in (to monitor everything)
echo and run 'Profile Migration Tool.bat' file to begin the migration process.
echo While everything is migrating, verify the user knows how to map network drives
echo and printers.
echo restart in 20 seconds.
(
echo Profile Rebuilt
echo Backup up EFS Certificates to desktop.
echo Network drives and printers backed up to a text file on user's desktop.
echo Appended 'old_' to the beginning of the local profile name and the date and time of rebuild to the end.
echo Backup of the profile registry key exported the old profile's 'Contacts' folder.
echo Agent instructed the user to log in.
echo Copied the Profile Migration Tool to the user's Desktop.
echo Data copied from old profile, EFS certificates restored ) | clip
echo.
echo A copy of all steps taken have been sent to the clipboard. Please paste these into your ticket.
SET tmout=10
PING 1.2.1.2 -n 1 -w %tmout%000 > NUL
goto :beginning