@@ -100,8 +100,9 @@ try {
100
100
# This block will catch the error and suppress it.
101
101
}
102
102
New-Item - ItemType Directory - Force - Path " $ScratchDisk \scratchdir" > $null
103
- Mount-WindowsImage - ImagePath $ScratchDisk \tiny11\sources\install.wim - Index $index - Path $ScratchDisk \scratchdir
103
+ Mount-WindowsImage - ImagePath $wimFilePath - Index $index - Path $ScratchDisk \scratchdir
104
104
105
+ # Powershell dism module does not have direct equivalent for /Get-Intl
105
106
$imageIntl = & dism / English / Get-Intl " /Image:$ ( $ScratchDisk ) \scratchdir"
106
107
$languageLine = $imageIntl -split ' \n' | Where-Object { $_ -match ' Default system UI language : ([a-zA-Z]{2}-[a-zA-Z]{2})' }
107
108
@@ -112,41 +113,37 @@ if ($languageLine) {
112
113
Write-Host " Default system UI language code not found."
113
114
}
114
115
115
- $imageInfo = & ' dism' ' /English' ' /Get-WimInfo' " /wimFile:$ ( $ScratchDisk ) \tiny11\sources\install.wim" " /index:$index "
116
- $lines = $imageInfo -split ' \r?\n'
117
-
118
- foreach ($line in $lines ) {
119
- if ($line -like ' *Architecture : *' ) {
120
- $architecture = $line -replace ' Architecture : ' , ' '
121
- # If the architecture is x64, replace it with amd64
122
- if ($architecture -eq ' x64' ) {
123
- $architecture = ' amd64'
124
- }
125
- Write-Host " Architecture: $architecture "
126
- break
127
- }
116
+ # Defined in (Microsoft.Dism.Commands.ImageInfoObject).Architecture formatting script
117
+ # 0 -> x86, 5 -> arm(currently unused), 6 -> ia64(currently unused), 9 -> x64, 12 -> arm64
118
+ switch ((Get-WindowsImage - ImagePath $wimFilePath - Index $index ).Architecture)
119
+ {
120
+ 0 { $architecture = " x86" }
121
+ 9 { $architecture = " amd64" }
122
+ 12 {$architecture = " arm64" }
128
123
}
129
124
130
- if (-not $architecture ) {
125
+ if (Test-Path variable:architecture) {
126
+ Write-Host " Architecture: $architecture "
127
+ } else {
131
128
Write-Host " Architecture information not found."
132
129
}
133
130
131
+
134
132
Write-Host " Mounting complete! Performing removal of applications..."
135
133
136
- $packages = & ' dism ' ' /English ' " /image: $ ( $ ScratchDisk) \scratchdir" ' /Get-ProvisionedAppxPackages ' |
134
+ $packages = Get-ProvisionedAppxPackage - Path " $ ScratchDisk \scratchdir" |
137
135
ForEach-Object {
138
- if ($_ -match ' PackageName : (.*)' ) {
139
- $matches [1 ]
140
- }
136
+ $_.PackageName
141
137
}
142
- $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_'
138
+
139
+ $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_'
143
140
144
141
$packagesToRemove = $packages | Where-Object {
145
142
$packageName = $_
146
143
$packagePrefixes -contains ($packagePrefixes | Where-Object { $packageName -like " $_ *" })
147
144
}
148
145
foreach ($package in $packagesToRemove ) {
149
- & ' dism ' ' /English ' " /image: $ ( $ ScratchDisk) \scratchdir" ' /Remove-ProvisionedAppxPackage ' " /PackageName: $package "
146
+ Remove-AppxProvisionedPackage - Path " $ ScratchDisk \scratchdir" - PackageName " $package "
150
147
}
151
148
152
149
@@ -391,7 +388,7 @@ Write-Host "Unmounting image..."
391
388
Dismount-WindowsImage - Path $ScratchDisk \scratchdir - Save
392
389
Write-Host " Exporting image..."
393
390
# Compressiontype Recovery is not supported with PShell https://learn.microsoft.com/en-us/powershell/module/dism/export-windowsimage?view=windowsserver2022-ps#-compressiontype
394
- Export-WindowsImage - SourceImagePath $ScratchDisk \tiny11\sources\install.wim - SourceIndex $index - DestinationImagePath $ScratchDisk \tiny11\sources\install2.wim - CompressionType Fast
391
+ Export-WindowsImage - SourceImagePath $ScratchDisk \tiny11\sources\install.wim - SourceIndex $index - DestinationImagePath $ScratchDisk \tiny11\sources\install2.wim - CompressionType Maximum
395
392
Remove-Item - Path " $ScratchDisk \tiny11\sources\install.wim" - Force | Out-Null
396
393
Rename-Item - Path " $ScratchDisk \tiny11\sources\install2.wim" - NewName " install.wim" | Out-Null
397
394
Write-Host " Windows image completed. Continuing with boot.wim."
0 commit comments