Skip to content

Handling for install.wim greater than 4GB #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
11 changes: 10 additions & 1 deletion Public/New-OSBuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
#=================================================
Expand Down
59 changes: 55 additions & 4 deletions Public/New-OSDBuilderUSB.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand All @@ -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
Expand All @@ -47,14 +80,15 @@ function New-OSDBuilderUSB {

$AllMyOSDBMedia = @()
$AllMyOSDBMedia = [array]$AllMyOSMedia + [array]$AllMyOSBuilds + [array]$AllMyPEBuilds

}

Process {
Write-Host '========================================================================================' -ForegroundColor DarkGray
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'
Expand All @@ -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
Expand All @@ -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 {
Expand Down