From 1ab4093d54b7d9bda9f47d7819694e66ae8de357 Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Wed, 27 Aug 2025 12:40:11 -0700 Subject: [PATCH] Refactor: Enhance artifact cleanup for disabled features Renames `Remove-DisabledUpdates` to `Remove-DisabledArtifacts` to better reflect its expanded scope. This function now also removes Office installation scripts and downloaded content if the Office installation is disabled via the `$InstallOffice` flag. The function call is moved to run before app installations to ensure artifacts are removed prior to the installation phase. --- FFUDevelopment/BuildFFUVM.ps1 | 39 ++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/FFUDevelopment/BuildFFUVM.ps1 b/FFUDevelopment/BuildFFUVM.ps1 index f5d4fe2..259ae95 100644 --- a/FFUDevelopment/BuildFFUVM.ps1 +++ b/FFUDevelopment/BuildFFUVM.ps1 @@ -579,10 +579,11 @@ if (-not $AppListPath) { $AppListPath = "$AppsPath\AppList.json" } if (-not $UserAppListPath) { $UserAppListPath = "$AppsPath\UserAppList.json" } if (-not $OrchestrationPath) { $OrchestrationPath = "$AppsPath\Orchestration" } if (-not $wingetWin32jsonFile) { $wingetWin32jsonFile = "$OrchestrationPath\WinGetWin32Apps.json" } -if (-not $InstallDefenderPath) { $installDefenderPath = "$OrchestrationPath\Update-Defender.ps1" } -if (-not $InstallMSRTPath) { $installMSRTPath = "$OrchestrationPath\Update-MSRT.ps1" } -if (-not $InstallODPath) { $installODPath = "$OrchestrationPath\Update-OneDrive.ps1" } -if (-not $InstallEdgePath) { $installEdgePath = "$OrchestrationPath\Update-Edge.ps1" } +if (-not $InstallOfficePath) { $InstallOfficePath = "$OrchestrationPath\Install-Office.ps1" } +if (-not $InstallDefenderPath) { $InstallDefenderPath = "$OrchestrationPath\Update-Defender.ps1" } +if (-not $InstallMSRTPath) { $InstallMSRTPath = "$OrchestrationPath\Update-MSRT.ps1" } +if (-not $InstallODPath) { $InstallODPath = "$OrchestrationPath\Update-OneDrive.ps1" } +if (-not $InstallEdgePath) { $InstallEdgePath = "$OrchestrationPath\Update-Edge.ps1" } if (-not $AppsScriptVarsJsonPath) { $AppsScriptVarsJsonPath = "$OrchestrationPath\AppsScriptVariables.json" } if (-not $DeployISO) { $DeployISO = "$FFUDevelopmentPath\WinPE_FFU_Deploy_$WindowsArch.iso" } if (-not $CaptureISO) { $CaptureISO = "$FFUDevelopmentPath\WinPE_FFU_Capture_$WindowsArch.iso" } @@ -3597,7 +3598,26 @@ function Remove-FFU { Remove-Item -Path $FFUCaptureLocation\*.ffu -Force WriteLog "Removal complete" } -Function Remove-DisabledUpdates { +Function Remove-DisabledArtifacts { + # Remove Office artifacts if Install Office is disabled + if (-not $InstallOffice) { + $removed = $false + if (Test-Path -Path $installOfficePath) { + WriteLog "Install Office disabled - removing $installOfficePath" + Remove-Item -Path $installOfficePath -Force -ErrorAction SilentlyContinue + $removed = $true + } + if (Test-Path -Path $OfficePath) { + WriteLog 'Removing Office and ODT download' + $OfficeDownloadPath = "$OfficePath\Office" + Remove-Item -Path $OfficeDownloadPath -Recurse -Force -ErrorAction SilentlyContinue + Remove-Item -Path "$OfficePath\setup.exe" -Recurse -Force -ErrorAction SilentlyContinue + $removed = $true + } + if ($removed) { WriteLog 'Removal complete' } + } + + # Remove Defender artifacts if Defender update is disabled if (-not $UpdateLatestDefender) { $removed = $false @@ -4925,7 +4945,10 @@ if ($InstallApps) { WriteLog "$($app.name)" } } - + + # Remove residual update artifacts for any updates disabled via flags + Remove-DisabledArtifacts + #Install Office if ($InstallOffice) { #Check if Office has already been downloaded, if so, skip download @@ -4952,10 +4975,6 @@ if ($InstallApps) { } - - # Remove residual update artifacts for any updates disabled via flags - Remove-DisabledUpdates - #Update Latest Defender Platform and Definitions - these can't be serviced into the VHDX, will be saved to AppsPath if ($UpdateLatestDefender) { # Check if Defender has already been downloaded, if so, skip download