I'd like to make a batch file that:

  1. Opens the Command Prompt
  2. Mounts an .ISO
  3. Then runs:

    DISM /Online /Cleanup-Image /StartComponentCleanup
    DISM /Online /Cleanup-Image /AnalyzeComponentStore
    DISM /Online /Cleanup-Image /RestoreHealth /source:WIM:F:\Sources\Install.wim:1 /LimitAccess

How would I go about doing that? I already know how to create a .bat file and how to run it as admin. Thanks in advance for your answers!

  • mounting an ISO try this: powershell.exe "Mount-DiskImage ""%WindowsISO%"""
    – cybernard
    Jun 20, 2016 at 3:25
  • So your problem isn't actually running commands after another, but to mount an ISO? Jun 20, 2016 at 8:13

1 Answer 1


There are two options how to mount ISO using script: to use powershell Mount-DiskImage commandlet (follow the link to see the ready how-to answer) or to use an external utility PowerISO in a batch file. Due to your question was about batch file here is an example with PowerISO:

piso mount d:\test.iso F:
DISM /Online /Cleanup-Image /StartComponentCleanup
DISM /Online /Cleanup-Image /AnalyzeComponentStore
DISM /Online /Cleanup-Image /RestoreHealth /source:WIM:F:\Sources\Install.wim:1 /LimitAccess

You don't need an extra command to open command prompt - when running batch file it will start command prompt by itself. In this example you mount file test.iso located on D: drive to a virtual drive F:

You will also need to specify the real path to piso.exe in the batch file.

  • So would this be correct? Imgur. And to make sure I got this right: They would run one after the other (once the previous has finished) or will they all 'try' to run at the same time?
    – Akres
    Jun 20, 2016 at 11:51
  • No, you can't use PowerShell commands inside the batch script. You either do it completely as PowerShell script from scratch or as batch.
    – Hardoman
    Jun 20, 2016 at 13:26
  • all the commands here can run as-is on powershell without problem, so just open powershell and paste them, or save as a *.ps1 file then run. Of course if for some reason cmd is required then you can run powershell from cmd
    – phuclv
    Jul 29, 2021 at 16:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .