Public/Functions/split/Convert-EsdToFolder.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
function Convert-EsdToFolder { [CmdletBinding(PositionalBinding = $false)] param ( [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [Alias('FullName')] [string]$esdFullName, [string]$folderFullName = $null ) #================================================= # Blocks #================================================= Block-StandardUser Block-WindowsVersionNe10 Block-WindowsReleaseIdLt1703 #================================================= # Test-WindowsImage #================================================= $TestWindowsImage = Test-WindowsImage -ImagePath $esdFullName #================================================= # Test Destination #================================================= if ($TestWindowsImage) { $esdGetItem = Get-Item -Path $esdFullName -ErrorAction Stop if (! ($folderFullName)) { $folderFullName = Join-Path $esdGetItem.Directory $esdGetItem.BaseName } if (Test-Path $folderFullName) { Write-Warning "Delete exiting folder at $folderFullName" Break } else { try { New-Item -Path $folderFullName -ItemType Directory -Force -ErrorAction Stop | Out-Null } catch { Write-Warning "New-Item failed $folderFullName" $folderFullName = $(Join-Path $env:TEMP $(Get-Random)) New-Item -Path $folderFullName -ItemType Directory -Force -ErrorAction Stop | Out-Null } } #================================================= # Build #================================================= Write-Verbose -Verbose "ESD will be expanded to $folderFullName" $esdGetWindowsImage = Get-WindowsImage -ImagePath $esdGetItem.FullName -ErrorAction Stop foreach ($esdWindowsImage in $esdGetWindowsImage) { if ($esdWindowsImage.ImageName -eq 'Windows Setup Media') { Write-Verbose -Verbose "Expanding Index $($esdWindowsImage.ImageIndex) $($esdWindowsImage.ImageName)" Expand-WindowsImage -ImagePath "$($esdWindowsImage.ImagePath)" -ApplyPath "$folderFullName" -Index "$($esdWindowsImage.ImageIndex)" -ErrorAction SilentlyContinue | Out-Null } elseif ($esdWindowsImage.ImageName -like "*Windows PE*") { Write-Verbose -Verbose "Exporting Index $($esdWindowsImage.ImageIndex) $($esdWindowsImage.ImageName)" Export-WindowsImage -SourceImagePath "$($esdWindowsImage.ImagePath)" -SourceIndex $($esdWindowsImage.ImageIndex) -DestinationImagePath "$folderFullName\sources\boot.wim" -CompressionType Max -ErrorAction SilentlyContinue | Out-Null } elseif ($esdWindowsImage.ImageName -like "*Windows Setup*") { Write-Verbose -Verbose "Exporting Index $($esdWindowsImage.ImageIndex) $($esdWindowsImage.ImageName)" Export-WindowsImage -SourceImagePath "$($esdWindowsImage.ImagePath)" -SourceIndex $($esdWindowsImage.ImageIndex) -DestinationImagePath "$folderFullName\sources\boot.wim" -CompressionType Max -Setbootable -ErrorAction SilentlyContinue | Out-Null } else { Write-Verbose -Verbose "Exporting Index $($esdWindowsImage.ImageIndex) $($esdWindowsImage.ImageName)" Export-WindowsImage -SourceImagePath "$($esdWindowsImage.ImagePath)" -SourceIndex $($esdWindowsImage.ImageIndex) -DestinationImagePath "$folderFullName\sources\install.wim" -CompressionType Max -ErrorAction SilentlyContinue | Out-Null } } #================================================= # Get-Item #================================================= Get-Item -Path $folderFullName #================================================= } } |