mirror of
https://github.com/ntdevlabs/tiny11builder.git
synced 2025-03-13 18:15:30 +00:00
update: powershell dism feature and provisoned appx
- Get architecture using Get-WindowsImage and its property directly. - Use Get-AppxProvisionedPackage and Remove-AppxProvisionedPackage instead if dism for more consistence. - Use Export-WindowsImage with -CompressionType Maximum instead of Fast for smaller type(used to be recovery with dism.exe).
This commit is contained in:
parent
e1273fe6ca
commit
f1e79e8d16
@ -122,7 +122,7 @@ $packages = & 'dism' '/English' "/image:$($env:SystemDrive)\scratchdir" '/Get-Pr
|
|||||||
$matches[1]
|
$matches[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$packagePrefixes = 'Clipchamp.Clipchamp_', 'Microsoft.SecHealthUI_', 'Microsoft.Windows.PeopleExperienceHost_', 'Microsoft.Windows.PinningConfirmationDialog_', 'Windows.CBSPreview_', 'Microsoft.BingNews_', 'Microsoft.BingWeather_', 'Microsoft.GamingApp_', 'Microsoft.GetHelp_', 'Microsoft.Getstarted_', 'Microsoft.MicrosoftOfficeHub_', 'Microsoft.MicrosoftSolitaireCollection_', 'Microsoft.People_', 'Microsoft.PowerAutomateDesktop_', 'Microsoft.Todos_', 'Microsoft.WindowsAlarms_', 'microsoft.windowscommunicationsapps_', 'Microsoft.WindowsFeedbackHub_', 'Microsoft.WindowsMaps_', 'Microsoft.WindowsSoundRecorder_', 'Microsoft.Xbox.TCUI_', 'Microsoft.XboxGamingOverlay_', 'Microsoft.XboxGameOverlay_', 'Microsoft.XboxSpeechToTextOverlay_', 'Microsoft.YourPhone_', 'Microsoft.ZuneMusic_', 'Microsoft.ZuneVideo_', 'MicrosoftCorporationII.MicrosoftFamily_', 'MicrosoftCorporationII.QuickAssist_', 'MicrosoftTeams_', 'Microsoft.549981C3F5F10_'
|
$packagePrefixes = 'Clipchamp.Clipchamp_', 'Microsoft.SecHealthUI_', 'Microsoft.Windows.PeopleExperienceHost_', 'Microsoft.Windows.PinningConfirmationDialog_', 'Windows.CBSPreview_', 'Microsoft.BingNews_', 'Microsoft.BingWeather_', 'Microsoft.GamingApp_', 'Microsoft.GetHelp_', 'Microsoft.Getstarted_', 'Microsoft.MicrosoftOfficeHub_', 'Microsoft.MicrosoftSolitaireCollection_', 'Microsoft.People_', 'Microsoft.PowerAutomateDesktop_', 'Microsoft.Todos_', 'Microsoft.WindowsAlarms_', 'microsoft.windowscommunicationsapps_', 'Microsoft.WindowsFeedbackHub_', 'Microsoft.WindowsMaps_', 'Microsoft.WindowsSoundRecorder_', 'Microsoft.Xbox.TCUI_', 'Microsoft.XboxGamingOverlay_', 'Microsoft.XboxGameOverlay_', 'Microsoft.XboxSpeechToTextOverlay_', 'Microsoft.YourPhone_', 'Microsoft.ZuneMusic_', 'Microsoft.ZuneVideo_', 'MicrosoftCorporationII.MicrosoftFamily_', 'MicrosoftCorporationII.QuickAssist_', 'MicrosoftTeams_', 'MSTeams_', 'Microsoft.549981C3F5F10_'
|
||||||
|
|
||||||
$packagesToRemove = $packages | Where-Object {
|
$packagesToRemove = $packages | Where-Object {
|
||||||
$packageName = $_
|
$packageName = $_
|
||||||
|
@ -100,8 +100,9 @@ try {
|
|||||||
# This block will catch the error and suppress it.
|
# This block will catch the error and suppress it.
|
||||||
}
|
}
|
||||||
New-Item -ItemType Directory -Force -Path "$ScratchDisk\scratchdir" > $null
|
New-Item -ItemType Directory -Force -Path "$ScratchDisk\scratchdir" > $null
|
||||||
Mount-WindowsImage -ImagePath $ScratchDisk\tiny11\sources\install.wim -Index $index -Path $ScratchDisk\scratchdir
|
Mount-WindowsImage -ImagePath $wimFilePath -Index $index -Path $ScratchDisk\scratchdir
|
||||||
|
|
||||||
|
# Powershell dism module does not have direct equivalent for /Get-Intl
|
||||||
$imageIntl = & dism /English /Get-Intl "/Image:$($ScratchDisk)\scratchdir"
|
$imageIntl = & dism /English /Get-Intl "/Image:$($ScratchDisk)\scratchdir"
|
||||||
$languageLine = $imageIntl -split '\n' | Where-Object { $_ -match 'Default system UI language : ([a-zA-Z]{2}-[a-zA-Z]{2})' }
|
$languageLine = $imageIntl -split '\n' | Where-Object { $_ -match 'Default system UI language : ([a-zA-Z]{2}-[a-zA-Z]{2})' }
|
||||||
|
|
||||||
@ -112,41 +113,37 @@ if ($languageLine) {
|
|||||||
Write-Host "Default system UI language code not found."
|
Write-Host "Default system UI language code not found."
|
||||||
}
|
}
|
||||||
|
|
||||||
$imageInfo = & 'dism' '/English' '/Get-WimInfo' "/wimFile:$($ScratchDisk)\tiny11\sources\install.wim" "/index:$index"
|
# Defined in (Microsoft.Dism.Commands.ImageInfoObject).Architecture formatting script
|
||||||
$lines = $imageInfo -split '\r?\n'
|
# 0 -> x86, 5 -> arm(currently unused), 6 -> ia64(currently unused), 9 -> x64, 12 -> arm64
|
||||||
|
switch ((Get-WindowsImage -ImagePath $wimFilePath -Index $index).Architecture)
|
||||||
foreach ($line in $lines) {
|
{
|
||||||
if ($line -like '*Architecture : *') {
|
0 { $architecture = "x86" }
|
||||||
$architecture = $line -replace 'Architecture : ',''
|
9 { $architecture = "amd64" }
|
||||||
# If the architecture is x64, replace it with amd64
|
12 {$architecture = "arm64" }
|
||||||
if ($architecture -eq 'x64') {
|
|
||||||
$architecture = 'amd64'
|
|
||||||
}
|
|
||||||
Write-Host "Architecture: $architecture"
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not $architecture) {
|
if (Test-Path variable:architecture) {
|
||||||
|
Write-Host "Architecture: $architecture"
|
||||||
|
} else {
|
||||||
Write-Host "Architecture information not found."
|
Write-Host "Architecture information not found."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Write-Host "Mounting complete! Performing removal of applications..."
|
Write-Host "Mounting complete! Performing removal of applications..."
|
||||||
|
|
||||||
$packages = & 'dism' '/English' "/image:$($ScratchDisk)\scratchdir" '/Get-ProvisionedAppxPackages' |
|
$packages = Get-ProvisionedAppxPackage -Path "$ScratchDisk\scratchdir" |
|
||||||
ForEach-Object {
|
ForEach-Object {
|
||||||
if ($_ -match 'PackageName : (.*)') {
|
$_.PackageName
|
||||||
$matches[1]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$packagePrefixes = 'Clipchamp.Clipchamp_', 'Microsoft.BingNews_', 'Microsoft.BingWeather_', 'Microsoft.GamingApp_', 'Microsoft.GetHelp_', 'Microsoft.Getstarted_', 'Microsoft.MicrosoftOfficeHub_', 'Microsoft.MicrosoftSolitaireCollection_', 'Microsoft.People_', 'Microsoft.PowerAutomateDesktop_', 'Microsoft.Todos_', 'Microsoft.WindowsAlarms_', 'microsoft.windowscommunicationsapps_', 'Microsoft.WindowsFeedbackHub_', 'Microsoft.WindowsMaps_', 'Microsoft.WindowsSoundRecorder_', 'Microsoft.Xbox.TCUI_', 'Microsoft.XboxGamingOverlay_', 'Microsoft.XboxGameOverlay_', 'Microsoft.XboxSpeechToTextOverlay_', 'Microsoft.YourPhone_', 'Microsoft.ZuneMusic_', 'Microsoft.ZuneVideo_', 'MicrosoftCorporationII.MicrosoftFamily_', 'MicrosoftCorporationII.QuickAssist_', 'MicrosoftTeams_', 'Microsoft.549981C3F5F10_'
|
|
||||||
|
$packagePrefixes = 'Clipchamp.Clipchamp_', 'Microsoft.BingNews_', 'Microsoft.BingWeather_', 'Microsoft.GamingApp_', 'Microsoft.GetHelp_', 'Microsoft.Getstarted_', 'Microsoft.MicrosoftOfficeHub_', 'Microsoft.MicrosoftSolitaireCollection_', 'Microsoft.People_', 'Microsoft.PowerAutomateDesktop_', 'Microsoft.Todos_', 'Microsoft.WindowsAlarms_', 'microsoft.windowscommunicationsapps_', 'Microsoft.WindowsFeedbackHub_', 'Microsoft.WindowsMaps_', 'Microsoft.WindowsSoundRecorder_', 'Microsoft.Xbox.TCUI_', 'Microsoft.XboxGamingOverlay_', 'Microsoft.XboxGameOverlay_', 'Microsoft.XboxSpeechToTextOverlay_', 'Microsoft.YourPhone_', 'Microsoft.ZuneMusic_', 'Microsoft.ZuneVideo_', 'MicrosoftCorporationII.MicrosoftFamily_', 'MicrosoftCorporationII.QuickAssist_', 'MicrosoftTeams_', 'MSTeams_', 'Microsoft.549981C3F5F10_'
|
||||||
|
|
||||||
$packagesToRemove = $packages | Where-Object {
|
$packagesToRemove = $packages | Where-Object {
|
||||||
$packageName = $_
|
$packageName = $_
|
||||||
$packagePrefixes -contains ($packagePrefixes | Where-Object { $packageName -like "$_*" })
|
$packagePrefixes -contains ($packagePrefixes | Where-Object { $packageName -like "$_*" })
|
||||||
}
|
}
|
||||||
foreach ($package in $packagesToRemove) {
|
foreach ($package in $packagesToRemove) {
|
||||||
& 'dism' '/English' "/image:$($ScratchDisk)\scratchdir" '/Remove-ProvisionedAppxPackage' "/PackageName:$package"
|
Remove-AppxProvisionedPackage -Path "$ScratchDisk\scratchdir" -PackageName "$package"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -391,7 +388,7 @@ Write-Host "Unmounting image..."
|
|||||||
Dismount-WindowsImage -Path $ScratchDisk\scratchdir -Save
|
Dismount-WindowsImage -Path $ScratchDisk\scratchdir -Save
|
||||||
Write-Host "Exporting image..."
|
Write-Host "Exporting image..."
|
||||||
# Compressiontype Recovery is not supported with PShell https://learn.microsoft.com/en-us/powershell/module/dism/export-windowsimage?view=windowsserver2022-ps#-compressiontype
|
# Compressiontype Recovery is not supported with PShell https://learn.microsoft.com/en-us/powershell/module/dism/export-windowsimage?view=windowsserver2022-ps#-compressiontype
|
||||||
Export-WindowsImage -SourceImagePath $ScratchDisk\tiny11\sources\install.wim -SourceIndex $index -DestinationImagePath $ScratchDisk\tiny11\sources\install2.wim -CompressionType Fast
|
Export-WindowsImage -SourceImagePath $ScratchDisk\tiny11\sources\install.wim -SourceIndex $index -DestinationImagePath $ScratchDisk\tiny11\sources\install2.wim -CompressionType Maximum
|
||||||
Remove-Item -Path "$ScratchDisk\tiny11\sources\install.wim" -Force | Out-Null
|
Remove-Item -Path "$ScratchDisk\tiny11\sources\install.wim" -Force | Out-Null
|
||||||
Rename-Item -Path "$ScratchDisk\tiny11\sources\install2.wim" -NewName "install.wim" | Out-Null
|
Rename-Item -Path "$ScratchDisk\tiny11\sources\install2.wim" -NewName "install.wim" | Out-Null
|
||||||
Write-Host "Windows image completed. Continuing with boot.wim."
|
Write-Host "Windows image completed. Continuing with boot.wim."
|
||||||
|
Loading…
Reference in New Issue
Block a user