I keep getting a Cannot Mount <Windows Edition Here> (specifically Pro Education) and it'll just close powershell afterwards. Any ideas? This is using the 4.0.1.9-b4 files.
Close and open the powershell window and rerun the command, delete also by hand any offline_temp dir.
I found code on Stack Overflow to remove all the variables the script uses but it doesn't help with the persistent temp file. Here is the output though, so it IS working. Code: Creating a Package Summary Log. Post-Optimization Image Health State: [Healthy] Saving and Dismounting Windows 10 Enterprise Rebuilding and Exporting Windows 10 Enterprise using Maximum compression. Optimizing the Installation Media File Structure. Creating a No-Prompt Bootable Windows Installation Media ISO. Finalizing Optimizations. Optimize-Offline completed in [8] minutes with [0] errors. Removing the following variables: _ Additional ApplyUnattendParams appsToRemove AppxPackages Capabilities capabilitiesToRemove ComponentCleanup CompressionType DaRT Dedup DeveloperMode DisableDefenderOptionalFeature DisabledFeatures DisableFeatureParams DisableOptionalFeatureParams DismountInstallParams EnabledFeatures EnableFeatureParams ExpandCalcParams ExportInstallParams Feature FeaturesToDisable FeaturesToDisableList FeaturesToEnable FeaturesToEnableList foreach ImageFiles ImageIndex InboxAppsKey InboxAppsPackages InstallDriverParams InstallInfo InstallWim ISO ISOExport ISOFile ISOMedia ISOMount Item JSON LayoutTemplate MCPShell MCPShortcut MicrosoftEdge MountInstallParams OptimizeTimer PackageKey PackageLog Packages packagesToRemove populateLists PSCmdlet PSItem Registry RemoveAppxParams RemoveCapabilityParams RemovedAppxPackages RemovedSystemApps RemovePackageParams RET SaveDirectory SelectiveRegistry SourcePath StorageHistoryCharts switch SystemApps Visibility Win32Calc WindowsApps WindowsCapabilities WindowsPackages WindowsStore PS D:\Optimize-Offline-master3\Optimize-Offline-master3>
Isn't the below code how the Godhand unloaded all the variables etc. and you need to make signature blocks for the ones you added? I'm not 100% sure, but something to look into. Edit: I think the signature block is just identifying the code as his, but what about the #region Post-Processing Block And this. Code: Begin { #region Pre-Processing Block $LocalScope | Add-Member -MemberType NoteProperty -Name Variables -Value (Get-Variable).Name -PassThru | Add-Member -MemberType NoteProperty -Name ErrorActionPreference -Value $ErrorActionPreference -PassThru | Add-Member -MemberType NoteProperty -Name ProgressPreference -Value $ProgressPreference $ErrorActionPreference = 'SilentlyContinue' $Global:ProgressPreference = 'SilentlyContinue' $Host.UI.RawUI.BackgroundColor = 'Black' Clear-Host Test-Requirements If (Get-WindowsImage -Mounted) { Dismount-Images; Clear-Host } [Void](Clear-WindowsCorruptMountPoint) ((GetPath -Path $Env:SystemRoot -Child 'Logs\DISM\dism.log'), (GetPath -Path $Env:SystemRoot -Child 'Logs\CBS\CBS.log')) | Purge -ErrorAction Ignore $Global:Error.Clear() #endregion Pre-Processing Block } Code: #endregion Image Finalization } End { #region Post-Processing Block ((Compare-Object -ReferenceObject (Get-Variable).Name -DifferenceObject $LocalScope.Variables).InputObject).ForEach{ Remove-Variable -Name $PSItem -ErrorAction Ignore } $ErrorActionPreference = $LocalScope.ErrorActionPreference $Global:ProgressPreference = $LocalScope.ProgressPreference $Global:Error.Clear() #endregion Post-Processing Block } } # SIG # Begin signature block # MIIIDgYJKoZIhvcNAQcCoIIH/zCCB/sCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB # gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR # AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUXJK+Xcwr5UtDXk+8Ez5D9SK1 # 78qgggV7MIIFdzCCBF+gAwIBAgITGgAAABuiU/ojidF4nQAAAAAAGzANBgkqhkiG # 9w0BAQsFADBFMRQwEgYKCZImiZPyLGQBGRYEVEVDSDEVMBMGCgmSJomT8ixkARkW # BU9NTklDMRYwFAYDVQQDEw1PTU5JQy5URUNILUNBMB4XDTIwMDUxNjExNTAzOFoX # DTIxMDUxNjExNTAzOFowUzEUMBIGCgmSJomT8ixkARkWBFRFQ0gxFTATBgoJkiaJ # k/IsZAEZFgVPTU5JQzEOMAwGA1UEAxMFVXNlcnMxFDASBgNVBAMTC0JlblRoZUdy # ZWF0MIIBIjANB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skf3JUHYgW+AJ3wRJkyqVxq3YY7saq0vcWNy0mFR7krGy # ZJxcbvILN0jSivUZpBWFVYdkd4FzOFtm6OFE3whzMFAQpo8+A1qm7xjpvwjcrrgp # MjY= # SIG # End signature block
Here is my Windows 11 log. Code: *************************************************************************************************** Running Module : Optimize-Offline 4.0.1.7 Optimize Start : 08/08/2021 08:31:42 PM Identity Name : Kedar Computer Name : KEDARWOLF-PC *************************************************************************************************** 2021-08-08T20:31:42 [INFO]: Supported Image Build: [22000] 2021-08-08T20:31:45 [INFO]: Mounting Windows 11 Enterprise 2021-08-08T20:32:30 [INFO]: Pre-Optimization Image Health State: [Healthy] 2021-08-08T20:32:35 [INFO]: Removing Provisioned App Package: Microsoft.BingNews 2021-08-08T20:32:38 [INFO]: Removing Provisioned App Package: Microsoft.BingWeather 2021-08-08T20:32:41 [INFO]: Removing Provisioned App Package: Microsoft.GetHelp 2021-08-08T20:32:44 [INFO]: Removing Provisioned App Package: Microsoft.Getstarted 2021-08-08T20:32:46 [INFO]: Removing Provisioned App Package: Microsoft.MicrosoftOfficeHub 2021-08-08T20:32:49 [INFO]: Removing Provisioned App Package: Microsoft.MicrosoftSolitaireCollection 2021-08-08T20:32:52 [INFO]: Removing Provisioned App Package: Microsoft.MicrosoftStickyNotes 2021-08-08T20:32:55 [INFO]: Removing Provisioned App Package: Microsoft.Paint 2021-08-08T20:32:57 [INFO]: Removing Provisioned App Package: Microsoft.People 2021-08-08T20:33:00 [INFO]: Removing Provisioned App Package: Microsoft.ScreenSketch 2021-08-08T20:33:03 [INFO]: Removing Provisioned App Package: Microsoft.SecHealthUI 2021-08-08T20:33:06 [INFO]: Removing Provisioned App Package: Microsoft.Windows.Photos 2021-08-08T20:33:09 [INFO]: Removing Provisioned App Package: Microsoft.WindowsAlarms 2021-08-08T20:33:11 [INFO]: Removing Provisioned App Package: Microsoft.WindowsCalculator 2021-08-08T20:33:14 [INFO]: Removing Provisioned App Package: Microsoft.WindowsCamera 2021-08-08T20:33:17 [INFO]: Removing Provisioned App Package: microsoft.windowscommunicationsapps 2021-08-08T20:33:21 [INFO]: Removing Provisioned App Package: Microsoft.WindowsFeedbackHub 2021-08-08T20:33:23 [INFO]: Removing Provisioned App Package: Microsoft.WindowsMaps 2021-08-08T20:33:26 [INFO]: Removing Provisioned App Package: Microsoft.WindowsNotepad 2021-08-08T20:33:29 [INFO]: Removing Provisioned App Package: Microsoft.WindowsSoundRecorder 2021-08-08T20:33:32 [INFO]: Removing Provisioned App Package: Microsoft.YourPhone 2021-08-08T20:33:35 [INFO]: Removing Provisioned App Package: Microsoft.ZuneMusic 2021-08-08T20:33:38 [INFO]: Removing Provisioned App Package: Microsoft.ZuneVideo 2021-08-08T20:33:47 [INFO]: Removing System App: Microsoft.AAD.BrokerPlugin 2021-08-08T20:33:49 [INFO]: Removing System App: Microsoft.BioEnrollment 2021-08-08T20:33:51 [INFO]: Removing System App: Microsoft.ECApp 2021-08-08T20:33:53 [INFO]: Removing System App: Microsoft.LockApp 2021-08-08T20:33:55 [INFO]: Removing System App: Microsoft.Win32WebViewHost 2021-08-08T20:33:57 [INFO]: Removing System App: Microsoft.Windows.AddSuggestedFoldersToLibarayDialog 2021-08-08T20:34:00 [INFO]: Removing System App: Microsoft.Windows.FileExplorer 2021-08-08T20:34:02 [INFO]: Removing System App: Microsoft.Windows.FilePicker 2021-08-08T20:34:04 [INFO]: Removing System App: Microsoft.Windows.ParentalControls 2021-08-08T20:34:06 [INFO]: Removing System App: Microsoft.Windows.PeopleExperienceHost 2021-08-08T20:34:09 [INFO]: Removing System App: NcsiUwpApp 2021-08-08T20:34:11 [INFO]: Removing System App: Windows.CBSPreview 2021-08-08T20:34:14 [INFO]: Disabling Services, Drivers and Integration Content for Removed Apps. 2021-08-08T20:34:19 [INFO]: Removing Windows Biometric Capability Packages. 2021-08-08T20:34:28 [INFO]: Disabling Optional Feature: Windows-Defender-Default-Definitions 2021-08-08T20:34:32 [INFO]: Importing Custom App Associations. 2021-08-08T20:34:36 [INFO]: Removing Windows Capability: App.StepsRecorder 2021-08-08T20:34:39 [INFO]: Removing Windows Capability: App.Support.QuickAssist 2021-08-08T20:34:43 [INFO]: Removing Windows Capability: MathRecognizer 2021-08-08T20:34:47 [INFO]: Removing Windows Capability: Microsoft.Windows.Ethernet.Client.Intel.E1i68x64 2021-08-08T20:34:52 [INFO]: Removing Windows Capability: Microsoft.Windows.Ethernet.Client.Intel.E2f68 2021-08-08T20:34:55 [INFO]: Removing Windows Capability: Microsoft.Windows.Notepad.System 2021-08-08T20:34:59 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Broadcom.Bcmpciedhd63 2021-08-08T20:35:03 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Broadcom.Bcmwl63a 2021-08-08T20:35:07 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Broadcom.Bcmwl63al 2021-08-08T20:35:11 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Intel.Netwbw02 2021-08-08T20:35:16 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Intel.Netwew00 2021-08-08T20:35:20 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Intel.Netwew01 2021-08-08T20:35:25 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Intel.Netwlv64 2021-08-08T20:35:30 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Intel.Netwns64 2021-08-08T20:35:34 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Intel.Netwsw00 2021-08-08T20:35:38 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Intel.Netwtw02 2021-08-08T20:35:45 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Intel.Netwtw04 2021-08-08T20:35:51 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Intel.Netwtw06 2021-08-08T20:35:56 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Intel.Netwtw08 2021-08-08T20:36:01 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Marvel.Mrvlpcie8897 2021-08-08T20:36:05 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Qualcomm.Athw8x 2021-08-08T20:36:10 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Qualcomm.Athwnx 2021-08-08T20:36:16 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Qualcomm.Qcamain10x64 2021-08-08T20:36:21 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Ralink.Netr28x 2021-08-08T20:36:26 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Realtek.Rtl8187se 2021-08-08T20:36:30 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Realtek.Rtl8192se 2021-08-08T20:36:35 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Realtek.Rtl819xp 2021-08-08T20:36:39 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Realtek.Rtl85n64 2021-08-08T20:36:44 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Realtek.Rtwlane 2021-08-08T20:36:49 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Realtek.Rtwlane01 2021-08-08T20:36:54 [INFO]: Removing Windows Capability: Microsoft.Windows.Wifi.Client.Realtek.Rtwlane13 2021-08-08T20:36:59 [INFO]: Removing Windows Capability: Microsoft.Windows.WordPad 2021-08-08T20:37:04 [INFO]: Removing Windows Capability: OneCoreUAP.OneSync 2021-08-08T20:37:09 [INFO]: Removing Windows Capability: OpenSSH.Client 2021-08-08T20:37:16 [INFO]: Removing Windows Package: Microsoft-Windows-LanguageFeatures-Handwriting-en-us 2021-08-08T20:37:21 [INFO]: Removing Windows Package: Microsoft-Windows-LanguageFeatures-OCR-en-us 2021-08-08T20:37:25 [INFO]: Removing Windows Package: Microsoft-Windows-LanguageFeatures-Speech-en-us 2021-08-08T20:37:35 [INFO]: Disabling Optional Feature: MicrosoftWindowsPowerShellV2Root 2021-08-08T20:37:42 [INFO]: Disabling Optional Feature: MSRDC-Infrastructure 2021-08-08T20:37:46 [INFO]: Disabling Optional Feature: Printing-XPSServices-Features 2021-08-08T20:37:51 [INFO]: Disabling Optional Feature: SmbDirect 2021-08-08T20:37:55 [INFO]: Disabling Optional Feature: WorkFolders-Client 2021-08-08T20:38:02 [INFO]: Enabling Optional Feature: Microsoft-Windows-Subsystem-Linux 2021-08-08T20:38:10 [INFO]: Integrating the Win32 Calculator. 2021-08-08T20:38:13 [INFO]: Applying Optimized Registry Settings. 2021-08-08T20:38:25 [INFO]: Applying Setup Content. 2021-08-08T20:38:28 [INFO]: Importing Registry Template: Additional Tweaks.reg 2021-08-08T20:38:34 [INFO]: Applying Answer File. 2021-08-08T20:38:37 [INFO]: Injecting Driver Packages into Windows 11 Enterprise 2021-08-08T20:39:22 [INFO]: Cannot perform a clean-up of the Component Store while there are pending installations. 2021-08-08T20:39:22 [INFO]: Cleaning-up the Start Menu Layout. 2021-08-08T20:39:25 [INFO]: Disabling automatic driver update 2021-08-08T20:39:26 [INFO]: Enabling dormant OneDrive fix 2021-08-08T20:39:28 [INFO]: Creating a Package Summary Log. 2021-08-08T20:39:35 [INFO]: Post-Optimization Image Health State: [Healthy] 2021-08-08T20:39:38 [INFO]: Saving and Dismounting Windows 11 Enterprise 2021-08-08T20:41:08 [INFO]: Rebuilding and Exporting Windows 11 Enterprise using Solid compression. 2021-08-08T20:48:51 [INFO]: Optimizing the Installation Media File Structure. 2021-08-08T20:48:51 [INFO]: Creating a No-Prompt Bootable Windows Installation Media ISO. 2021-08-08T20:48:52 [INFO]: Finalizing Optimizations. 2021-08-08T20:48:53 [INFO]: Optimize-Offline completed in [17] minutes with [0] errors. *************************************************************************************************** Optimizations Finalized : 08/08/2021 08:48:53 PM ***************************************************************************************************
I think there is something there. It looks to me like he's only removing variables created by his script rather than the more brutal solution of globally removing all the variables system-wide. I updated my post just prior to yours #1189 I think unlocking the PowerShell console handle might be a solution? or possibly . . . If you look at Optimize-Offline\Src\Public\Dismount-Images.ps1 and/or Optimize-Offline\Src\Public\Invoke-Cleanup.ps1 and/or Optimize-Offline\Src\Public\Remove-Container.ps1 Maybe adding a one or two or more "sleep" timeouts between commands or possibly even repeating unmount/Purge commands with sleep timeouts in between might work around the Windows timing "race condition" flaw?
In order to get populate lists to work, I had to comment that line out. I'm just starting to wrap my head around configuring this awesome tool. Thanks guys! Code: ./Start-Optimize populateLists
something must be wrong with the code if you cant clear temp directories despite doing the (unnecessary) manually clearing of variables and forcing garbage collection everything should already be under a scriptblock {} that cleans after itself when out of scope automatically, so I guess it must be because of some external tool call (in that case, isolating the call in another scriptblock would help) or it's because of the whole modules thing - it makes no sense for an unpublished to a gallery, portable script to use modules, when functions can do everything and wont suffer from weird quirks I might be wrong since I never run this project, but will try to give it a shot and provide feedback
I'm getting this error while runnning OO Code: Failed to Create a No-Prompt Bootable Windows Installation Media ISO. I created a win 10 ISO from uup edited win10ui to remove Code: del /f /q "!target!\efi\microsoft\boot\*noprompt.*" %_Nul3% ran it and updated the iso made before Added attached lists to content folder and then ran the script Configuration.json is same as described on the guide with the change being instead of solid it's set to maximum is there something i am missing?
I ran into the same thing. All one has to do is select "Enable EFI" in Vbox Settings \ System \ Motherboard I should say also, I changed to Prompt
You need to delete the extracted ISO source for W10UI and extract it again. If you just update the source you ran W10UI on already, you get that error.
The problem relies in powershell.exe process locking the files. Yes those blocks are executed at the beginning and at the end of the script. And they should remove variable used doring the powershell session.
I set up some remove variable code in the script that removes ALL the variables the script uses, and temp file still doesn't get removed, so I think it is some other issue. See this post. https://forums.mydigitallife.net/th...20h1-and-ltsc-2019.80038/page-60#post-1680995 Edit: Could it be my code runs AFTER the delete temp folder code? It's right at the end of the script. Second Edit: I'll share the modifications I made to the script when I get home from work, so you can debug it. @gdeliana Here is the code I added and got working. Code: ### Start of script (store list of existing variable names) $ExistingVariables = Get-Variable | Select-Object -ExpandProperty Name ### End of script (remove new variables) $NewVariables = Get-Variable | Select-Object -ExpandProperty Name | Where-Object {$ExistingVariables -notcontains $_ -and $_ -ne "ExistingVariables"} if ($NewVariables) { Write-Host "Removing the following variables:`n`n$NewVariables" Remove-Variable $NewVariables } else { Write-Host "No new variables to remove!" }