Optimize-Offline Guide - Windows Debloating Tool, Windows 1803, 1903, 19H2, 1909, 20H1 and LTSC 2019

Discussion in 'Windows 10' started by KedarWolf, Jul 30, 2019.

    ok no issues.
     
  1. SerpentDash

    SerpentDash MDL Novice

    Jul 17, 2019
    8
    7
    0
    Optimize-Offline 4.0.1.8 should support 19043 (21H1) but I still get:
    WARNING: Unsupported Image Build: [19043]

    As I understand correctly, as 4.0.1.8 supports 19043 build so there might be some optimalizations for this build so bypassing $InstallInfo.Build if statement shouldn't be the case here. Any idea how to fix this?
     
  2. drew84

    drew84 MDL Expert

    Mar 13, 2014
    1,402
    2,391
    60
    It has been a long time since I've had a good look at this project but, Optimize-Offline.psm1
    lines 452, 495 and 615 change If ($InstallInfo.Build -xx '19041') to If ($InstallInfo.Build -xx '19043')
    should do the trick
     
  3. drew84

    drew84 MDL Expert

    Mar 13, 2014
    1,402
    2,391
    60
    For those interested - Optimize-Offline.psm1 changes from 4.0.17 to 4.0.18

    Lines 62, 63, 80 added {Mostly Changelog Notes}

    Lines 243, 452, 495 changed from -ge to -le {could be the issue for 19043 - change most likely be 4.0.17 copy using for comparison was previously altered by myself}

    Line 615 changed from -ge to -lt { - again change most likely be 4.0.17 copy using for comparison was previously altered by myself}

    Line Removed (originally placed after line 261)
    Code:
    If ($InstallInfo.Build -eq '19041' -and $Dedup.IsPresent) { $Dedup = ![Switch]::Present }
    
    Line 662 added
    Code:
      $DynamicParams.BioEnrollment = $true
    
    Lines 739 to 751 added
    Code:
               If ($DynamicParams.BioEnrollment -and (Get-WindowsCapability -Path $InstallMount -Name *Hello* -ScratchDirectory $ScratchFolder -LogPath $DISMLog -LogLevel 1 | Where-Object -Property State -EQ Installed))
               {
                   Try
                   {
                       Log $OptimizeData.RemovingBiometricCapability
                       [Void](Get-WindowsCapability -Path $InstallMount -Name *Hello* -ScratchDirectory $ScratchFolder -LogPath $DISMLog -LogLevel 1 | Where-Object -Property State -EQ Installed | Remove-WindowsCapability -Path $InstallMount -ScratchDirectory $ScratchFolder -LogPath $DISMLog -LogLevel 1 -ErrorAction Stop)
                   }
                   Catch
                   {
                       Log $OptimizeData.FailedRemovingBiometricCapability -Type Error -ErrorRecord $Error[0]
                       Start-Sleep 3
                   }
               }
    
    Line 961 changed

    $RET = StartExe $DISM -Arguments ('/Image:"{0}" /Add-Package /PackagePath:"{1}" /ScratchDir:"{2}" /LogPath:"{3}" /LogLevel:1' -f $InstallMount, (GetPath -Path $DevModeExpand.FullName -Child update.mum), $ScratchFolder, $DISMLog) -ErrorAction Stop

    1595 t0 1624 added
    Code:
           #region Component Store Clean-up
           If ($ComponentCleanup.IsPresent)
           {
               If (!(Test-Path -Path (GetPath -Path $InstallMount -Child 'Windows\WinSxS\pending.xml')))
               {
                   Log ($OptimizeData.ComponentStoreCleanup -f $InstallInfo.Name)
                   If ($InstallInfo.Build -ge '18362') { $RegClean = 3 }
                   Else { $RegClean = 0 }
                   RegHives -Load
                   RegKey -Path "HKLM:\WIM_HKLM_SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide\Configuration" -Name "DisableResetbase" -Value 1 -Type DWord
                   RegKey -Path "HKLM:\WIM_HKLM_SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide\Configuration" -Name "SupersededActions" -Value $RegClean -Type DWord
                   RegHives -Unload
                   Try
                   {
                       $RET = StartExe $DISM -Arguments ('/Image:"{0}" /Cleanup-Image /StartComponentCleanup /ScratchDir:"{1}" /LogPath:"{2}" /LogLevel:1' -f $InstallMount, $ScratchFolder, $DISMLog) -ErrorAction Stop
                       If ($RET -eq 0) { $DynamicParams.ComponentCleanup = $true }
                       Else { Throw }
                   }
                   Catch
                   {
                       Log ($OptimizeData.FailedComponentStoreCleanup -f $InstallInfo.Name) -Type Error
                   }
               }
               Else
               {
                   Log $OptimizeData.ComponentStorePendingInstallations
               }
           }
           #endregion Component Store Clean-up
    
    Line 1985 Changed

    @($TempDirectory, (GetPath -Path $Env:SystemRoot -Child 'Logs\DISM\dism.log'), (GetPath -Path $Env:SystemRoot -Child 'Logs\CBS\CBS.log')) | Purge -ErrorAction Ignore
     
  4. SerpentDash

    SerpentDash MDL Novice

    Jul 17, 2019
    8
    7
    0
    And change line 243:
    ... -and $InstallInfo.Build -le '19041') -> ... -and $InstallInfo.Build -le '19043')

    and add this after line 1300:
    19043 { '21H1'; Break }
     
  5. spanishfly

    spanishfly MDL Senior Member

    Dec 5, 2018
    365
    540
    10
    #806 spanishfly, Jun 27, 2021
    Last edited: Jul 20, 2021
    Edit 4 July 2021
    • Clarifying the steps needed to disable Microsoft.SecHealthUI (Defender)
    Edit 28June 2021: Added
    • retained/removed provisioned app packages
    • retained/removed System apps
    27 June initial post: Optimized Windows 11 Education 21996.1
    From C:\Optimize-Offline.txt: "This Windows 11 Education installation was optimized with Optimize-Offline version 4.0.1.7"

    == Windows 11 ==
    Optimize-Offline v4.0.1.8 doesn't officially support Windows 11. You have to modify the Optimize-Offline.psm1 script to get it to work with Windows 11.
    @@ Edit Optimize-Offline.psm1 @@
    To get Optimize-Offline.psm1 v4.0.1.8 to work with Windows 11 . . .
    - Change line 243 to: -
    Code:
    If ($InstallInfo.Build -ge '17134' -and $InstallInfo.Build -ge '19041')
    == Microsoft.SecHealthUI (Defender) [Part one - editing the script] ==
    Optimize-Offline.psm1 expects to find SecHealthUI in with the other System apps. In Windows 11, the SecHealthUI (defender) package has moved to the Appx location.
    @@ Editing Optimize-Offline.psm1 (Defender Mod) @@
    [Details] The code change forces Optimize-Offline v4.0.1.8 to apply all the defender disabling registry code that normally gets applied if you choose to disable Microsoft.SecHealthUI as a System App. You're disabling Microsoft.SecHealthUI as a "Metro" appx (provisioned app package) so you have to let Optimize-Offline.psm1 know what to do. Savvy?
    Warning! Don't make this change if your keeping Microsoft.SecHealthUI (Defender)
    Only make the next code change if you're optimizing Windows 11 and removing Defender!
    To get Optimize-Offline.psm1 v4.0.1.8 to fully disable SecHealthUI (Defender). . .
    - Change line 687 to: -
    Code:
    If ($InstallInfo.Build -ge '19041')
    Also! Don't worry about line 731. If you study the code, you'll see that you want to leave that line as-is.
    You can check that the additional defender code ran successfully by looking in the "Optimize-Offline.log" for:
    Code:
    [INFO]: Disabling Optional Feature: Windows-Defender-Default-Definitions
    == Microsoft.SecHealthUI (Defender) [Part two - disabling the appx package ] ==
    Optimize-Offline provides you several ways to disable appx packages. I prefer to use the AppxWhitelist.json.
    I "disable" the Microsoft.SecHealthUI provisioned app package by *not* including it in my whitelist.
    Using my suggested whitelist, leaves seven total retained (active) provisioned app packages.
    My AppxWhitelist.json retains six and Windows 11 adds "Microsoft.MicrosoftEdge.Stable" making seven.
    My AppxWhitelist.json
    Code:
    {
      "DisplayName": [
    "Microsoft.PowerAutomateDesktop",
    "Microsoft.StorePurchaseApp",
    "Microsoft.UI.Xaml.2.4",
    "Microsoft.VCLibs.140.00",
    "Microsoft.WindowsStore",
    "MicrosoftWindows.Client.WebExperience"
    ]
    }
    Microsoft.549981C3F5F10
    Microsoft.BingNews
    Microsoft.BingWeather
    Microsoft.DesktopAppInstaller
    Microsoft.GamingApp
    Microsoft.GetHelp
    Microsoft.Getstarted
    Microsoft.HEIFImageExtension
    Microsoft.MicrosoftOfficeHub
    Microsoft.MicrosoftSolitaireCollection
    Microsoft.MicrosoftStickyNotes
    Microsoft.Paint
    Microsoft.People
    Microsoft.ScreenSketch
    *Microsoft.SecHealthUI*
    Microsoft.Todos
    Microsoft.VP9VideoExtensions
    Microsoft.WebMediaExtensions
    Microsoft.WebpImageExtension
    Microsoft.Windows.Photos
    Microsoft.WindowsAlarms
    Microsoft.WindowsCalculator
    Microsoft.WindowsCamera
    microsoft.windowscommunicationsapps
    Microsoft.WindowsFeedbackHub
    Microsoft.WindowsMaps
    Microsoft.WindowsNotepad
    Microsoft.WindowsSoundRecorder
    Microsoft.WindowsTerminal
    Microsoft.Xbox.TCUI
    Microsoft.XboxGameOverlay
    Microsoft.XboxGamingOverlay
    Microsoft.XboxIdentityProvider
    Microsoft.XboxSpeechToTextOverlay
    Microsoft.YourPhone
    Microsoft.ZuneMusic
    Microsoft.ZuneVideo

    Microsoft.Windows.AppResolverUX
    Microsoft.AccountsControl
    Microsoft.AsyncTextService
    Microsoft.CredDialogHost
    Microsoft.Windows.Apprep.ChxApp
    Microsoft.Windows.AssignedAccessLockApp
    Microsoft.Windows.CapturePicker
    Microsoft.Windows.CloudExperienceHost
    Microsoft.Windows.NarratorQuickStart
    Microsoft.Windows.OOBENetworkCaptivePortal
    Microsoft.Windows.OOBENetworkConnectionFlow
    Microsoft.Windows.PinningConfirmationDialog
    Microsoft.Windows.Search
    Microsoft.Windows.ShellExperienceHost
    Microsoft.Windows.StartMenuExperienceHost
    MicrosoftWindows.Client.CBS
    MicrosoftWindows.UndockedDevKit
    NcsiUwpApp
    windows.immersivecontrolpanel
    Windows.PrintDialog

    Microsoft.AAD.BrokerPlugin
    Microsoft.BioEnrollment
    Microsoft.ECApp
    Microsoft.LockApp
    Microsoft.MicrosoftEdge
    Microsoft.MicrosoftEdgeDevToolsClient
    Microsoft.Win32WebViewHost
    Microsoft.Windows.AddSuggestedFoldersToLibarayDialog
    Microsoft.Windows.CallingShellApp
    Microsoft.Windows.ContentDeliveryManager
    Microsoft.Windows.FileExplorer
    Microsoft.Windows.FilePicker
    Microsoft.Windows.ParentalControls
    Microsoft.Windows.PeopleExperienceHost
    Microsoft.Windows.SecureAssessmentBrowser
    Microsoft.XboxGameCallableUI
    Microsoft.Windows.XGpuEjectDialog
    Windows.CBSPreview
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. drew84

    drew84 MDL Expert

    Mar 13, 2014
    1,402
    2,391
    60
    ... covered in post above

    you could also add 19042 { '20H2'; Break }

    but that particular section is (if I remember correctly) for DART package integration, which you may have an issue with, due to build number 19041
    ... don't use the package integration part of the script, so can't attest to this.
     
  7. SerpentDash

    SerpentDash MDL Novice

    Jul 17, 2019
    8
    7
    0
    #808 SerpentDash, Jun 29, 2021
    Last edited: Jun 30, 2021
    Does anyone have issue with unattend.xml or SetupComplete.cmd not working properly on 21h1?

    Basically, I copied my Unattend and Setup folder from Optimize-Offline 4.0.1.7 (with 20h2) to Optimize-Offline 4.0.1.8 (with 21h1).
    When installing Win 10 Pro 21h1 (19043.1081) only half of answer file is applied (like system locale, skip eula, hide wireless setup etc) but SynchronousCommands aren't applied at all. Also SetupComplete.cmd is not triggered after installation.
    Tested on clean iso (without removing anything using O-O) with the same result. Also for some reason, when I used addition edition (Pro for workstations) scripts actually worked.

    Any idea whats wrong and how can I fix this?

    Update
    After testing older build of windows I realized that on vm everything works fine.
    The problem occur only on real machine. Any idea what this can mean? (I can provide logs if needed)

    Last update
    After 2 days I still don't know whats wrong with my device...
    For those interested in how I workaround this, I added RunOnce key to registry to run some scripts from Setup/Scripts when oobe ends. Overall looks the same but using different aproach...
     
  8. zalim581

    zalim581 MDL Novice

    Aug 12, 2019
    30
    6
    0
    I cant create ISOs with 4.0.1.8. These are the errors:

    Code:
    Index     : 0
    Exception : 'D:\Optimize-Offline-4.0.1.8\OfflineTemp_1132315477\Win10_21H1_Turkish_x64' access denied to the path.
    Category  : WriteError: (D:\Opt...1H1_Turkish_x64:DirectoryInfo) [Move-Item], IOException
    ErrorID   : MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand
    Target    : D:\Optimize-Offline-4.0.1.8\OfflineTemp_1132315477\Win10_21H1_Turkish_x64
    Command   : If ($ISOMedia.Exists) { Move-Item -Path $ISOMedia.FullName -Destination $SaveDirectory.FullName }
    Script    : D:\Optimize-Offline-4.0.1.8\Optimize-Offline.psm1
    Line      : 1974
    Column    : 29
    
    Index     : 1
    Exception : You cannot call a method on a null-valued expression.
    Category  : InvalidOperation: (:) [], RuntimeException
    ErrorID   : InvokeMethodOnNull
    Target    :
    Command   : $ISOFile = New-Item -Path $WorkFolder -Name ($($InstallInfo.Edition).Replace(' ', '') + "_$($InstallInfo.Bu
                ild).iso") -ItemType File -Force -ErrorAction:$ErrorActionPreference
    Script    : D:\Optimize-Offline-4.0.1.8\Src\Public\New-ISOMedia.ps1
    Line      : 79
    Column    : 60
    
    Index     : 2
    Exception : The property 'CodeName' cannot be found on this object. Verify that the property exists and can be set.
    Category  : InvalidOperation: (:) [], RuntimeException
    ErrorID   : PropertyNotFound
    Target    :
    Command   : Else { $ImageData.CodeName = $CurrentVersion.BuildBranch.ToUpper().Split('_')[0] }
    Script    : D:\Optimize-Offline-4.0.1.8\Src\Public\Get-ImageData.ps1
    Line      : 75
    Column    : 28
    
    Code:
    ...
    2021-07-01T00:53:35 [ERROR]: Failed to Update the Image Metadata for the install.wim
    2021-07-01T00:53:38 [INFO]: Optimizing the Installation Media File Structure.
    2021-07-01T00:53:38 [INFO]: Creating a No-Prompt Bootable Windows Installation Media ISO.
    2021-07-01T00:53:39 [ERROR]: Failed to Create a No-Prompt Bootable Windows Installation Media ISO.
    ....
    
     
  9. KedarWolf

    KedarWolf MDL Addicted

    Mar 17, 2016
    977
    874
    30
    #811 KedarWolf, Jul 1, 2021
    Last edited: Jul 1, 2021
    (OP)
    Try installing ADK 2004.
     
  10. zalim581

    zalim581 MDL Novice

    Aug 12, 2019
    30
    6
    0
    Nope didnt work
     
  11. 1. He suggested ADK 2004 & your comment seems 2094.
    2. Plus 4.0.1.8 worked flawlessly at my end without even a single error . Author of this tool has a vast knowledge in "Sapien Powershell Studio".
    3. your config file might not be having correct parameter thatswhy it doesnt result in a Optimized Offline ISO or might be you have edited any of his ps scripts according to your needs.
     
  12. zalim581

    zalim581 MDL Novice

    Aug 12, 2019
    30
    6
    0
    1.There is nothing called adk 2094 so i installed adk 2004
    3. my config:
    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."
      ],
      "SourcePath": "D:\\Win10_21H1_x64.iso",
      "WindowsApps": "All",
      "SystemApps": true,
      "Capabilities": true,
      "Packages": true,
      "Features": true,
      "DeveloperMode": false,
      "WindowsStore": false,
      "MicrosoftEdge": false,
      "Win32Calc": false,
      "Dedup": false,
      "DaRT": [
      ],
      "Registry": true,
      "Additional": {
        "Setup": true,
        "Wallpaper": false,
        "SystemLogo": false,
        "LockScreen": false,
        "RegistryTemplates": false,
        "LayoutModification": false,
        "Unattend": false,
        "Drivers": false,
        "NetFx3": false
      },
      "ComponentCleanup": true,
      "ISO": "No-Prompt"
    }
    
    and no I didnt edit anything.
     
  13. It seems correct as per author of OO configs in his config file.
    Might be the directory in which you are using OO has a space in its name .
    Thats all from me i can help . Nothing else as Kedarwolf has more exp then me in this Project.
     
  14. drew84

    drew84 MDL Expert

    Mar 13, 2014
    1,402
    2,391
    60
    1. You had to have edited something, as without some needed modifications O-O will only work with en-US Culture

    2. You also need to check downloaded zip file properties to ensue the file isn't locked
     
  15. zalim581

    zalim581 MDL Novice

    Aug 12, 2019
    30
    6
    0
    #817 zalim581, Jul 1, 2021
    Last edited by a moderator: Jul 1, 2021
    Not sure where you got that idea from. It says at the start that "some optimizations are not available", it doesn't say it wont work? If it didnt work with regions other en-US, why would it warn you at the start about it instead of simply exiting the script.
    I did not edit the script.
     
  16. KedarWolf

    KedarWolf MDL Addicted

    Mar 17, 2016
    977
    874
    30
    #818 KedarWolf, Jul 1, 2021
    Last edited by a moderator: Jul 1, 2021
    (OP)
    The script is only designed for en-US ISOs. A long time ago I had it working with en-GB by renaming some folders and editing some of the script files but I have no idea if or what to edit now as I just use en-US ISOs.

    Edit: Here's what I did for en-GB but other languages I'll doubt it will work, the localization is for en-US and en-GB is quite similar. Things might be totally different in other languages.

    https://forums.mydigitallife.net/th...20h1-and-ltsc-2019.80038/page-11#post-1573297

    As well in the latest script I'd use Notepad++ and search for en-US in the various script files, might be more things you need to change from back then.

    AND, there is a localization file that needs to be translated from English i think to work with a different language. Check on the GitHub and do a ticket, you might be able to translate the file for Godhand and it might help it work for you.
     
  17. zalim581

    zalim581 MDL Novice

    Aug 12, 2019
    30
    6
    0
    I dont get it. Why does the script warn me about it then, instead of exiting completely and throws an error at the end of the process?
     
  18. zbigniew59

    zbigniew59 MDL Senior Member

    May 14, 2016
    373
    171
    10
    I have been using this script for a long time and I confirm that after appropriate modifications the newest scrypt works for me flawlessly on my iso pl-PL.
    I even debloated Win 11 without any errors.