How to Mount and Unmount ISO File in PowerShell
Introduction
In this blog post, we will walk through how to mount and unmount ISO file in PowerShell.
Solution
Mount ISO file using Mount-DiskImage cmdlet
Mount-DiskImage
is PowerShell cmdlet or command to mount ISO file. You need to specify the image path. In this case, we are trying to mount Ubuntu iso file.
Below is the script to achieve this task.
Mount-DiskImage -ImagePath "C:\Iso\ubuntu-22.04.1-desktop-amd64.iso"
The result for above command will look like below image:
To explore more about the command you can find the help as in following script:
Get-Help Mount-DiskImage
Unmount ISO file using Dismount-DiskImage cmdlet
To unmount iso file, you can use Dismount-DiskImage
cmdlet by specifying the image path. You do this if you remember the exact location of image file.
Dismount-DiskImage -ImagePath "C:\Iso\ubuntu-22.04.1-desktop-amd64.iso"
But, if you only remember the drive name, you can chain several commands to unmount the iso file.
Get-Volume -DriveLetter 'E' | Get-DiskImage | Dismount-DiskImage
The script above will try to find the image path based on mounted drive in drive E, then finally unmount it.
Conclusion
In conclusion, to mount and unmount ISO file in PowerShell we can use Mount-DiskImage
and Dismount-DiskImage
cmdlet respectively.