I will give you a cheap idea on how to test any code for this issue. Run the script ./Start-Optimize.ps1, don't close the powershell window, run ./your_test_script.ps1 with the code that has to delete offline_temp folder. If you find any code that manages to delete that folder, you have solved the issue
My code is just to remove the variables the script uses. But it's pretty much the last thing that runs on the script. It might need to run BEFORE the delete temp file code I think, or have the delete temp file code run AFTER this code. My PowerShell editing skills are terrible, I cannot implement that at all, why I shared it with you.
Here is a fun fact... have never experienced *.temp issue Edit2: Not entirely accurate, Only time i've encountered *.temp folder was when script terminated (prior to completion) with errors *.temp folder in said case contained the error logs. ... even today.. went and downloaded the latest (@gdeliana) master (from main page - not release page) removed Lines 24 + 25 ... only changed these because it was only recent change pertaining to temp files Code: Get-Variable | Remove-Variable; Get-Module | Remove-Module; $error.Clear(); Clear-Host and put back Lines 686 Code: Log $OptimizeData.TerminatingOptimizations + x88 to x91 Code: $TempDirectory | Purge -ErrorAction Continue refreshenv Exit(0) @($DISMLog, $(GetPath -Path $Env:SystemRoot -Child 'Logs\DISM\dism.log')) | Purge -ErrorAction Ignore Ran populate lists on .wim and .iso, also ran optimze on .wim and .iso, both (all 4) completed ... no issues,... no temp folder. Edit: have also aquired the habit of also closing all explorer windows (relating to script) prior to executing said (powershell) script ... with W10UI and UUP Dump, scripts fail to unmount folders if script root is open in explorer. Pretty sure it is not the case with this script, as it clears (apparently) active mount points prior to completion. hope this clarifies some points raised, apologies for late response --- still half asleep after heavy session,, cheers
Is this correct? Code: } Catch { Log $Error[0] } Finally { Log $OptimizeData.TerminatingOptimizations Dismount-Images $TempDirectory | Purge -ErrorAction Continue refreshenv Exit(0) @($DISMLog, $(GetPath -Path $Env:SystemRoot -Child 'Logs\DISM\dism.log')) | Purge -ErrorAction Ignore }
Ha! you've solved it! (I, think) Kill explorer This is of course another heavy-handed solution. But at least, this time, it is an actual solution! I have full trust that someone can come up with a less dramatic way of breaking the Windows Explorer "hooks/handles". [Environment] Optimize Fork package used: #1183 Sunday at 2212 Host OS: Windows 10 Education 1809 17763.557 Only ran tests using an ISO Test #1 - validate "testing" Configutation.json Run script with no code changes Used my "[3] minutes with [0] errors "testing" Configutation.json" (only makes a maximum compressed, single index ISO from any multi-index ISO source)Result: Fails as expected There was a left over *.temp folder filled with all sorts of content "[3] minutes with [0] errors "testing" Configutation.json" fails which implies that making mods is *NOT* the problem. Test #2 - single code change to Start-Optimize.ps1 Only change made: Comment-out the heavy-handed Variable/Module line 24. Add heavy-handed Kill explorer line: Code: #Get-Variable | Remove-Variable; Get-Module | Remove-Module; $error.Clear(); Clear-Host (Get-Process -Name explorer).Kill() Process: All Explorer windows shut. Taskbar restarts. Didn't touch the PC except to select an ISO index when requested.Result: All good! No *.temp folder Test #3 - populate lists Using same unrefreshed/stale PowerShell Console Run: ./Start-Optimize populateLists Process: All Explorer windows shut. Taskbar restarts.Result: All good! C:\Optimize-Offline\Content\Lists ... *Template JSON's updated Test #4 - Final Test - Reopen Optimize-Offline Explorer folder while the script is running Using same unrefreshed/stale PowerShell Console Up-arrow in console history and Run: ./Start-Optimize Process: All Explorer windows shut. Taskbar restarts. Reopened explorer window "C:\Optimize-Offline" while script was running and witnessed the temp folder which is now truly a temporary folderResult: All good! No *.temp folder Spoiler: [3] minutes with [0] errors "testing" Configutation.json Code: { "_Info": [ "This is a JSON based Configuration file for Optimize-Offline.", "Ensure proper formatting is used when editing the JSON parameter values.", "Boolean parameter values use true and false. String parameter values must be enclosed in double-quotes.", "WindowsApps, SystemApps, Capabilities, Packages : All | None | Select | Whitelist | Blacklist", "FeaturesToEnable, FeaturesToDisable : All | None | Select | List" ], "SourcePath": "C:\\Build\\OEM ISO\\21390.2025.210603-0227.CO_RELEASE_SVC_IM_CLIENTMULTI_X64FRE_EN-US.ISO", "WindowsApps": "None", "SystemApps": "None", "Capabilities": "None", "Packages": "None", "FeaturesToEnable": "None", "FeaturesToDisable": "None", "DeveloperMode": false, "WindowsStore": false, "MicrosoftEdge": false, "Win32Calc": false, "Dedup": false, "DaRT": [], "Registry": false, "Additional": { "Setup": false, "Wallpaper": false, "SystemLogo": false, "LockScreen": false, "RegistryTemplates": false, "LayoutModification": false, "Unattend": false, "Drivers": false, "NetFx3": false }, "ComponentCleanup": false, "ISO": "No-Prompt", "CompressionType": "Maximum", "SelectiveRegistry": { "DisableWindowsUpdate": false, "DisableDriverUpdate": false, "DormantOneDrive": false } }
i tried now with prompt instead of no-prompt and sadly still the same error i've attached logs here The version i'm using is the one with DIR2ISO integrated
Any particular reason for running it under powershell v7 and not on the more reliable crt (built-in) one? try it out in native powershell as well is this something recommended / done commonly? I personally dont see the point but of course I could add compatibility mode for it in the new snippet
i've set powershell 7 as default so i ran with that following your advice i tried it with inbuilt powershell and it worked Thank You sir i think some code messes with powershell 7 ( i may be wrong)
Hahahaha this bug has become legendary. Chill guys we will eventually find something, i mean it's not the end of the world even having to just open a new window, i am a bit busy right now but as soon as i get my hands free will try all your solutions posted here. Please when you have a solution post it with lines and filename. Also you can even fork my repo in github and make a PR
Good job, @gdeliana !! Saw on Github you fixed the temp directory issue, and I just tested it, it IS fixed!
... is it possible that @BAU's snippet RunAsTI could (be adapted to) do the trick, used in same way as DIR2ISO From RunAsTi
So I'm using beta 5 (thanks for fixing the Temp folder deletion bug) on the 22000.120 ISO and I got through like 90% of the script, carefully selecting the components to remove, and a single error killed the entire run. I accidentally selected items related to printing and it stopped the whole process. What would be very helpful is if it ignored the error and chose to not do whatever is killing the entire process. Thoughts? Code: 2021-08-11T06:36:30 [INFO]: Removing Windows Package: Microsoft-Windows-Printing-WFS-FoD 2021-08-11T06:36:34 [ERROR]: Failed to Remove Windows Packages. 2021-08-11T06:36:34 [INFO]: Discarding any Images and Terminating Optimizations.
I did a minor update of my "Blacklists (remove) and Whitelists (keep)" post showing changes I found using (./Start-Optimize populateLists) in Windows 10 dev Build 21390 (speculatively Windows 10 2022H1) Like Windows 11, SecHealthUI aka the Defender application is moved from System apps to provisional UWP appx.