:: This script was created by Matthew Wai at www.TenForums.com/members/matthew-wai.html
:: ... at the request of zbook at www.TenForums.com/members/zbook.html
:: Last updated on 2021-11-30.
::===================================================================================
@Echo off & Set "[-]=%ProgramData%\[-+_+-].cmd"
(Fsutil Dirty Query %SystemDrive%>Nul)&&(Del "%[-]%" 2>Nul&Goto [Run_it])
Echo @Echo off^&"%~f0">"%[-]%" & PowerShell start "%[-]%" -verb RunAs
If not %errorlevel%==0 (Del "%[-]%"&Exit) else (Exit /B)
:[Run_it]
Title   Collecting information... & mode con cols=50 lines=3
Echo.&Echo     The script is collecting information ...
For /F "tokens=*" %%# in ('"PowerShell (New-Object -ComObject Wscript.Shell).SpecialFolders(4)"') Do (Set "Desktop=%%#")
If not exist "%Desktop%" (Set "Desktop=%Desktop:~1%")
For /f "tokens=2 delims==" %%# in ('wmic OS Get localdatetime /value') Do (Set "Time=%%#")
Set "Year=%Time:~0,4%" 
Set "Month=%Time:~4,2%" 
Set "Day=%Time:~6,2%"
Set "Hour=%Time:~8,2%" 
Set "Minute=%Time:~10,2%" 
Set "Second=%Time:~12,2%"
Set "Date+Time=%Year%-%Month%-%Day%_%Hour%-%Minute%-%Second%" 
Set "[F]=%ProgramData%\TenForums.com"
(MD "%[F]%" 2>Nul) & Set "F=Upgrade_failure"
Set "Z=%[F]%\%F%_logs_%Date+Time%" 
If exist "%[F]%\Windows" RD /s /q "%[F]%\Windows" 
Set "R=Windows\Panther" 
For %%# in ("%[F]%\%F%_logs_*.zip") Do (Del "%%#")
Set "P=PowerShell Compress-Archive -Path" 
Set "D=-Update -DestinationPath"
Set "S=Windows.~WS\Sources" 
Set "W=Windows.~BT\Sources" 
If exist "%[F]%\Windows.~BT" RD /s /q "%[F]%\Windows.~BT" 
If exist "%[F]%\%S%\Panther" RD /s /q "%[F]%\%S%\Panther"

XCOPY "%WinDir%\Logs\MoSetup" "%[F]%\Windows\Logs\MoSetup\" /S
XCOPY "%SystemDrive%\$%W%\Rollback" "%[F]%\%W%\Rollback\" /S
XCOPY "%SystemDrive%\$%W%\Panther" "%[F]%\%W%\Panther\" /S
XCOPY "%SystemDrive%\%R%\UnattendGC" "%[F]%\%R%\UnattendGC\" /S 
XCOPY "%SystemDrive%\%R%\NewOS" "%[F]%\%R%\NewOS\" /S 
Copy "%SystemDrive%\%R%\setupact.log" "%[F]%\%R%\" & (MD "%[F]%\%S%\Panther")
Copy "%SystemDrive%\%R%\setuperr.log" "%[F]%\%R%\" 
Copy "%SystemDrive%\$%S%\Panther\setupact.log" "%[F]%\%S%\Panther\"
Copy "%SystemDrive%\$%S%\Panther\setuperr.log" "%[F]%\%S%\Panther\"
Copy "%WinDir%\setupapi.log" "%[F]%\Windows\" & (MD "%[F]%\Windows\inf")
Copy "%WinDir%\inf\setupapi.dev.log" "%[F]%\Windows\inf\"

Cls & Title  PowerShell is zipping the log files...& mode con cols=120 lines=10
If exist "%[F]%\Windows.~WS" (%P% "%[F]%\Windows.~WS" %D% %Z%) && (RD /s /q "%[F]%\Windows.~WS")
If exist "%[F]%\Windows.~BT" (%P% "%[F]%\Windows.~BT" %D% %Z%) && (RD /s /q "%[F]%\Windows.~BT")
If exist "%[F]%\Windows"     (%P% "%[F]%\Windows"     %D% %Z%) && (RD /s /q "%[F]%\Windows")
Move "%Z%.zip" "%Desktop%">Nul & Set "CMD=%[F]%\CMD.cmd" 
Set "#=Echo Echo" 
(Echo @echo off^&Title   Operations completed successfully.^&mode con cols=89 lines=14^&color 17 
%#%.
%#%  #######################################################################################
%#%  #                                                                                     #
%#%  #                             %F%_info.bat                                #
%#%  #                                                                                     #
%#%  #      The log files have been put into the following ZIP file on your desktop:       #
%#%  #                                                                                     #
%#%  #                      %F%_logs_%Date+Time%.zip                   #
%#%  #                                                                                     #
%#%  #      Please upload the file as an attachment to your post on Ten Forums.            #
%#%  #      Press any key to close this window.                                            #
%#%  #                                                                                     #
%#%  #######################################################################################
Echo Pause ^>nul ^& Exit)> "%CMD%" & Timeout 1 /nobreak>Nul
Start "" "%CMD%" & RD "%[F]%" 2>Nul & Exit