From a4cd349f455de7fc56f1c01b806b3aeb26897cec Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Fri, 16 Feb 2024 10:38:42 -0800 Subject: [PATCH] Refactor BuildFFUVM.ps1 script*** This commit refactors the BuildFFUVM.ps1 script by: - Changing the default value of FFUDevelopmentPath to $PSScriptRoot - Adding a new parameter RemoveFFU - Adding a new function Remove-FFU to remove all FFU files in the FFUCaptureLocation - Adding a conditional block to call Remove-FFU if RemoveFFU parameter is true --- FFUDevelopment/BuildFFUVM.ps1 | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/FFUDevelopment/BuildFFUVM.ps1 b/FFUDevelopment/BuildFFUVM.ps1 index 864747a..dc7d828 100644 --- a/FFUDevelopment/BuildFFUVM.ps1 +++ b/FFUDevelopment/BuildFFUVM.ps1 @@ -125,7 +125,7 @@ param( })] [string]$WindowsSKU = 'Pro', [ValidateScript({ Test-Path $_ })] - [string]$FFUDevelopmentPath = 'C:\FFUDevelopment', + [string]$FFUDevelopmentPath = $PSScriptRoot, [bool]$InstallApps, [bool]$InstallOffice, [Parameter(Mandatory = $false)] @@ -210,10 +210,11 @@ param( return $true })] [bool]$CopyDrivers, + [bool]$RemoveFFU, #Will be used in future release [bool]$CopyPPKG, - [bool]$CopyUnattend, - [bool]$RemoveFFU + [bool]$CopyUnattend + ) $version = '2402.1' @@ -1392,6 +1393,12 @@ function Get-FFUEnvironment { Remove-Item -Path "$FFUDevelopmentPath\dirty.txt" -Force WriteLog "Cleanup complete" } +function Remove-FFU{ + #Remove all FFU files in the FFUCaptureLocation + WriteLog "Removing all FFU files in $FFUCaptureLocation" + Remove-Item -Path $FFUCaptureLocation\*.ffu -Force + WriteLog "Removal complete" +} ###END FUNCTIONS @@ -1706,6 +1713,17 @@ If ($BuildUSBDrive) { throw $_ } } +If ($RemoveFFU){ + try { + Remove-FFU + } + catch { + Write-Host 'Removing FFU files failed' + Writelog "Removing FFU files failed with error $_" + throw $_ + } + +} #Clean up dirty.txt file Remove-Item -Path .\dirty.txt -Force | out-null Write-Host "Script complete"