4

What is the PowerShell equivalent to DISM's /Cleanup-Image in this command:

DISM /Image:%mounted_image% /Cleanup-Image /StartComponentCleanup /Resetbase /ScratchDir:%scratch_dir%

Within Use DISM in Windows PowerShell, there is no corresponding PowerShell cmdlet, so is this Repair-WindowsImage command the equivalent to the above command?

Repair-WindowsImage -Path $mounted_image -RestoreHealth -ScratchDirectory $scratch_dir
JW0914
  • 9,096
wolfrevo
  • 317

2 Answers2

3

The parameters of Dism commands are an almost 1:1 to the parameters of PowerShell's Dism cmdlets, with the main difference being cmdlets use - instead of /, coupled with some additional paraemeters, such as -ScratchDirectory, being supported for Package Servicing.

The man page for the equivalent Dism cmdlets is Use DISM in Windows PowerShell, which links to cmdlet Repair-WindowsImage:

  • Repair-WindowsImage <-Online | -Path> is the equivalent of:
    Dism </Online | /Image:> /Cleanup-Image
    
    • Repair-WindowsImage cmdlet command:
      Repair-WindowsImage -Path $mounted_image -RestoreHealth -ScratchDirectory $scratch_dir
      
      is not the equivalent of /StartComponentCleanup:
      # There is no /ScratchDirectory parameter:
        Dism /Image:$mounted_image /Cleanup-Image /StartComponentCleanup /Resetbase
      
      Instead, it's the equivalent of /RestoreHealth:
      Dism /Image:$mounted_image /Cleanup-Image /RestoreHealth
      

Correct Repair-WindowsImage command: (-ScratchDirectory not required)

Repair-WindowsImage -Path $mounted_image -StartComponentCleanup -ResetBase -ScratchDirectory $scratch_dir
  • If running against an online Windows image [%SystemDrive% | $env:SystemDrive], -Online is used in lieu of -Path, however one or the other must be specified:
    • -Online: services packages of an online [booted to] Windows image
      e.g. Dism /Online
    • -Path: services packages of an offline [non-booted to] Windows image
      e.g. Dism /Image:<path>

JW0914
  • 9,096
-2

I'm not sure about the other switches, but dism.exe /online /cleanup-image /restorehealth works perfectly fine in powershell.