diff --git a/Public/New-OSBuild.ps1 b/Public/New-OSBuild.ps1 index 59e478d..dd89231 100644 --- a/Public/New-OSBuild.ps1 +++ b/Public/New-OSBuild.ps1 @@ -88,9 +88,14 @@ function New-OSBuild { # -IncludeKB '4577010','4577015' [string[]]$IncludeKB, + [Alias('PPKG','ProvisioningPackage')] + [ValidatePattern(".*?\.ppkg$")] + [ValidateScript({Test-Path $_})] + [string]$PPKGPath, + #Pauses the function the Install.wim is dismounted #Useful for Testing - [Alias('PauseOS','PauseDismount')] + [switch]$PauseDismountOS = $global:SetOSDBuilder.NewOSBuildPauseDismountOS, #Pauses the function before WinPE is dismounted @@ -960,6 +965,10 @@ function New-OSBuild { #================================================= Add-ContentPack -PackType OSCapability Add-ContentPack -PackType OSPackages + if ($null -ne $PPKGPath){ + Write-Host -ForegroundColor Yellow "Adding $PPKGPath to $MountDirectory" + & DISM.exe /Image:$MountDirectory /Add-ProvisioningPackage /PackagePath:$PPKGPath + } Add-WindowsPackageOS Add-FeaturesOnDemandOS #================================================= diff --git a/Public/New-OSDBuilderUSB.ps1 b/Public/New-OSDBuilderUSB.ps1 index 9293ba5..afd1add 100644 --- a/Public/New-OSDBuilderUSB.ps1 +++ b/Public/New-OSDBuilderUSB.ps1 @@ -13,6 +13,13 @@ Full Path of the OSDBuilder Media .PARAMETER USBLabel Label for the USB Drive + +.PARAMETER Split +Split install.wim into multiple .swm files. This will be automatically set to $true if the file is reported to be over 4GB. + +.PARAMETER SplitSize +Dynamic parameter when "Split" is used. The desired size of the .swm files created when using the "Split" parameter. Note: The integer value should be in MB (ie. 4000 is 4GB) + #> function New-OSDBuilderUSB { [CmdletBinding()] @@ -21,9 +28,35 @@ function New-OSDBuilderUSB { [string]$FullName, [ValidateLength(1,11)] - [string]$USBLabel + [string]$USBLabel, + + [Parameter] + [Switch]$Split ) + dynamicparam { + if ($Split) { + $ParameterName = "SplitSize" + + $parameterAttribute = New-Object System.Management.Automation.ParameterAttribute + $parameterAttribute.HelpMessage = "Please enter the size you wish to split:" + $parameterAttribute.Mandatory = $true + + $validateAttribute = New-Object System.Management.Automation.ValidateNotNullOrEmptyAttribute + $attributeCollection = [System.Collections.ObjectModel.Collection[System.Attribute]]::new() + $attributeCollection.Add($parameterAttribute) + $attributeCollection.Add($validateAttribute) + + $dynParam1 = [System.Management.Automation.RuntimeDefinedParameter]::new( + $ParameterName, [Int32], $attributeCollection + ) + + $paramDictionary = [System.Management.Automation.RuntimeDefinedParameterDictionary]::new() + $paramDictionary.Add( $ParameterName, $dynParam1) + return $paramDictionary + } + } + Begin { #================================================= # Get-OSDBuilder @@ -47,6 +80,7 @@ function New-OSDBuilderUSB { $AllMyOSDBMedia = @() $AllMyOSDBMedia = [array]$AllMyOSMedia + [array]$AllMyOSBuilds + [array]$AllMyPEBuilds + } Process { @@ -54,7 +88,7 @@ function New-OSDBuilderUSB { Write-Host -ForegroundColor Green "$($MyInvocation.MyCommand.Name) PROCESS" Write-Warning "USB will be formatted FAT32" - Write-Warning "Install.wim larger than 4GB will FAIL" + Write-Warning "Install.wim larger than 4GB will be split into swm files, if the Split parameter is not already specified" #================================================= Write-Verbose '19.1.14 Select Source OSMedia' @@ -78,6 +112,15 @@ function New-OSDBuilderUSB { } $Results = Get-Disk | Where-Object {$_.Size/1GB -lt 33 -and $_.BusType -eq 'USB'} | Out-GridView -Title 'OSDBuilder: Select a USB Drive to FORMAT' -OutputMode Single | Clear-Disk -RemoveData -RemoveOEM -Confirm:$false -PassThru | New-Partition -UseMaximumSize -IsActive -AssignDriveLetter | Format-Volume -FileSystem FAT32 -NewFileSystemLabel $USBLabel + # Get install.wim size in MB + $WIMSize = (Get-Item "$($SelectedOSMedia.FullName)\OS\Sources\install.wim").Length/100000 + + # If the split parameter is not selected and install.wim is larger than 4000MB, set the split size to 4000MB + Switch ($Split){ + $true { Continue } + $false { if ( $WIMSize -gt 4000 ) { $SplitSize = 4000 } } + } + if ($null -eq $Results) { Write-Warning "No USB Drive was Found or Selected" Return @@ -86,9 +129,17 @@ function New-OSDBuilderUSB { Set-Location -Path "$($SelectedOSMedia.FullName)\OS\boot" bootsect.exe /nt60 "$($Results.DriveLetter):" - #Copy Files from ISO to USB - Copy-Item -Path "$($SelectedOSMedia.FullName)\OS\*" -Destination "$($Results.DriveLetter):" -Recurse -Verbose + #Copy Files from ISO to USB and split the install.wim if needed or if specified by the split parameter + if ($Split -eq $true -or $WIMSize -gt 4000){ + #Create .swm files from the install.wim and copy them over instead of the install.wim (keeps filesize down for FAT32) + New-Item -Path "$($Results.DriveLetter):\" -Name "Sources" -ItemType Directory -Force -Verbose + Dism /Split-Image /ImageFile:"$($SelectedOSMedia.FullName)\OS\Sources\install.wim" /SWMFile:"$($Results.DriveLetter):\Sources\install.swm" /FileSize:$SplitSize /Verbose + Copy-Item -Path "$($SelectedOSMedia.FullName)\OS\*" -Destination "$($Results.DriveLetter):" -Recurse -Exclude "$($SelectedOSMedia.FullName)\OS\Sources\install.wim" -Verbose + } else { + Copy-Item -Path "$($SelectedOSMedia.FullName)\OS\*" -Destination "$($Results.DriveLetter):" -Recurse -Verbose + } } + } End {