DISM Commands and then some….

To continue my post on DISM I wanted to share some that I have been working with and almost make a cheat sheet for those that might need them.

Get list of index from the install wim
powershell Get-WindowsImage -ImagePath "C:\Location\Of\Wim\install.wim"

Export WIM from ISO
Note: Index number is pulled from the above command
Dism /export-image /sourceimagefile:"C:\Location\Of\Wim\install.wim" /sourceindex:3 /destinationimagefile:C:\Export\Directory\Enterprise.wim

Mount an Image
Note: Index is always 1 if you have exported the image from the install.wim
Dism /Mount-Image /ImageFile:C:\Location\Of\Wim\Enterprise.wim /index:1 /MountDir:"C:\MountDirectory"

Un-mount Image (Committing the image)
Dism /Unmount-Image /MountDir:"C:\MountDir" /commit

Un-mount Image (Discarding the image)
Dism /Unmount-Image /MountDir:"C:\MountDir" /discard

Capture Image
dism /capture-image /imagefile:z:\Dir\To\Save\Wim\edtechjeff.wim /capturedir:c:\ /name:"custom image" /Compress:Max

Add Driver to WIM
DISM /Image:C:\MountDIR /Add-Driver /Driver:C:\Path\To\drivers\ /recurse /ForceUnsigned

Get Listing of Packages on WIM
dism /Image:C:\Mount\Dir /Get-Provisionedappxpackages

Remove Packages
Note: The output from the list of packages is used to complete these commmands.

dism /image:\images\mount /Remove-Provisionedappxpackage /PackageName:Microsoft.BingNews_4.2.27001.0_neutral_~8wekyb3d8bbwe
dism /image:\images\mount /Remove-Provisionedappxpackage /PackageName:Microsoft.BingWeather_4.53.33420.0_neutral~8wekyb3d8bbwe
dism /image:\images\mount /Remove-Provisionedappxpackage /PackageName:Microsoft.GamingApp_2021.427.138.0_neutral~8wekyb3d8bbwe
dism /image:\images\mount /Remove-Provisionedappxpackage /PackageName:Microsoft.MicrosoftOfficeHub_18.2204.1141.0_neutral~8wekyb3d8bbwe dism /image:\images\mount /Remove-Provisionedappxpackage /PackageName:Microsoft.MicrosoftSolitaireCollection_4.12.3171.0_neutral~8wekyb3d8bbwe dism /image:\images\mount /Remove-Provisionedappxpackage /PackageName:Microsoft.People_2020.901.1724.0_neutral~8wekyb3d8bbwe
dism /image:\images\mount /Remove-Provisionedappxpackage /PackageName:Microsoft.WindowsMaps_2022.2202.6.0_neutral~8wekyb3d8bbwe
dism /image:\images\mount /Remove-Provisionedappxpackage /PackageName:Microsoft.YourPhone_1.22022.147.0_neutral~8wekyb3d8bbwe
dism /image:\images\mount /Remove-Provisionedappxpackage /PackageName:Microsoft.ZuneMusic_11.2202.46.0_neutral~8wekyb3d8bbwe
dism /image:\images\mount /Remove-Provisionedappxpackage /PackageName:Microsoft.ZuneVideo_2019.22020.10021.0_neutral~8wekyb3d8bbwe dism /image:\images\mount /Remove-Provisionedappxpackage /PackageName:Microsoft.Xbox.TCUI_1.23.28004.0_neutral~8wekyb3d8bbwe
dism /image:\images\mount /Remove-Provisionedappxpackage /PackageName:Microsoft.XboxGameOverlay_1.47.2385.0_neutral~8wekyb3d8bbwe dism /image:\images\mount /Remove-Provisionedappxpackage /PackageName:Microsoft.XboxGamingOverlay_2.622.3232.0_neutral~8wekyb3d8bbwe dism /image:\images\mount /Remove-Provisionedappxpackage /PackageName:Microsoft.XboxIdentityProvider_12.50.6001.0_neutral~8wekyb3d8bbwe dism /image:\images\mount /Remove-Provisionedappxpackage /PackageName:Microsoft.XboxSpeechToTextOverlay_1.17.29001.0_neutral~_8wekyb3d8bbwe

One other method to remove the packages from the mounted WIM is by using powershell script and incorporate DISM. I do almost prefer powershell to do the removal due to the Version number does change from version to version of Windows so you would have to maintain the list. With powershell you can use just a list and it will do a pattern match. Here is the script.

Script to Remove Packages

$mountPath = "E:\Images\Mount"

$packages = dism /image:$mountPath /Get-ProvisionedAppxPackages | Select-String "PackageName : " | ForEach-Object { $_.Line.Split(':')[1].Trim() }

$patterns = @(
"Microsoft.Bing",
"Microsoft.MicrosoftOfficeHub",
"Microsoft.Office.OneNote",
"Microsoft.SkypeApp",
"Microsoft.Wallet",
"Microsoft.MicrosoftSolitaireCollection",
"Microsoft.People",
"Microsoft.WindowsMaps",
"Microsoft.YourPhone",
"Microsoft.Zune",
"Microsoft.Xbox*"
)

$packagesToRemove = @()

foreach ($pattern in $patterns) {
$matchingPackages = $packages | Where-Object { $_ -like $pattern }
$packagesToRemove += $matchingPackages
}

foreach ($package in $packagesToRemove) {
dism /image:$mountPath /Remove-ProvisionedAppxPackage /PackageName:$package
}

Hope these commands do help you like they helped me. Till next time.

Leave a comment