Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I mount and dismount ISO images from PowerShell in Windows 8 without 3rd party programs?

This question's original revision got me wondering if it's possible to mount an ISO via PowerShell in Windows 8.

share|improve this question

2 Answers 2

up vote 30 down vote accepted

Mount an ISO from command prompt

If you're sitting at a command prompt and need to mount an ISO, run the following command:

PowerShell Mount-DiskImage

This will invoke a PowerShell cmdlet. You will be prompted for the path of the ISOs you wish to mount. When you are done, leave the last one blank and push enter.

enter image description here

Tada! It's mounted:

enter image description here

Dismount an ISO

To dismount an ISO from PowerShell run Dismount-DiskImage and follow the prompt. If you only know the drive letter off the top of your head, and not the image path, use this command:

Get-Volume [Drive Letter] | Get-DiskImage | Dismount-DiskImage

This command will grab the drive you specifiy, find the disk image, and dismount it.

enter image description here

Mounting multiple ISOs and displaying drive letters

You can also use the -PassThru flag to store data passed to the command. Lets mount a few ISOs, display their drive letters, execute a file on one of the drives, and then dismount all the ISOs.

Mount the ISOs

 $MountedISOs=Mount-DiskImage -PassThru D:\Downloads\Ubuntu.iso,D:\Downloads\Windows8.iso,D:\Downloads\Server2012.iso

Display volume info for each ISO mounted using a foreach loop

 foreach($iso in $MountedISOs){Get-Volume -DiskImage $iso}     

List J drive

 ls J:\

Open a file

 start wubi.exe

enter image description here

To dismount the ISOs, use the following command:

 Dismount-DiskImage $MountedISOs.ImagePath

Testing the ISO

To build a simple script that checks if the ISO is attached and is in fact an ISO (vs. a VHD) I like to use -PassThru to store the object temporarily, and use the Get-DiskImage command to update the status of the DiskImage object. This will update the Attached property. The StorageType property will tell you whether the file is an ISO or VHD according to its file extension.

enter image description here

The StoreType of a VHD is 2, where an ISO will return 1. Here's the output of $UbuntuISO: enter image description here

This is the output of $Temp after mounting a VHD: (Mount-DiskImage can also mount VHDs!) enter image description here

Note that the attached property above is blank, despite the Mount-DiskImage command running without a hitch.

Keep in mind that the $UbuntuISO variable will not stay updated either: enter image description here


Technet: Mount-DiskImage

Technet: Dismount-DiskImage

share|improve this answer
2  
Damn, with all those new cmdlets in PowerShell Windows 8 starts to tickle. –  sinni800 Nov 4 '12 at 3:38
    
We can easily mount the image through the command C:\>explorer.exe imagepath, here we don't need of PS but for unmount there we have need the PS. –  avirk Nov 4 '12 at 5:49
1  
Is all inside Windows 8? I mean don't you need to install other programs??? –  SEARAS Nov 4 '12 at 6:10
1  
+1 Very nice indeed! This was precisely what I was hoping to find in Win8 so I could eventually add it to the end of my answer here, but you saved me the trouble. I really need to start boning up on my PS skills. :) Edit: Is there any cmdlet to test the innards and report whether the file is an ISO or VHD or something else entirely that's not supported? Or maybe a way to test the return value of Mount-DiskImage perhaps so code can be branched accordingly? –  Karan Nov 4 '12 at 15:38
1  
@Karan Finally got around to figuring that out =D It's not going to test the guts, and frankly I think that's overkill. But it will let us know if it's mounted and an ISO vs VHD without diving in to PowerShell error handling. –  Tanner Nov 9 '12 at 16:17

Normally, if you want to do this via the command line, you need a non-interactive method. You will want to use the -ImagePath switch to do this.

Thus, the command is:

PowerShell Mount-DiskImage -ImagePath \"C:\AbsolutePathTo\Image.iso\"

Remember that if you quote the absolute path (for containing spaces and other special characters), you need to escape the quotes.

To dismount an iso image, remember to quote it:

PowerShell "Get-Volume G | Get-DiskImage | Dismount-DiskImage"

Note that we did not have to quote the command in the first case, but we do in the second, because the | pipe will cause the command line to think that it is in the command line context, rather than addition arguments to PowerShell (which PowerShell automatically concatenates into a single command).

Also make sure to spell Dismount-DiskImage correctly (no k in Dismount).

share|improve this answer
    
What does the -Command switch do, and why run non-interactive? –  Tanner Nov 4 '12 at 17:14
1  
oops, didn't need -Command, it appears to do that automatically, non-interactive because chances are, a script is doing it rather than a human (who can just use the GUI) –  ronalchn Nov 4 '12 at 19:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.