Table of Contents
In this blog post, we will walk through how to mount and unmount ISO file in PowerShell.
Mount ISO file using PowerShell
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 Windows 10 iso file.
Mount-DiskImage -ImagePath "D:\ISOs\windows10.iso"
The result for above command will look like below:
Attached : True
BlockSize : 0
DevicePath : \\.\CDROM0
FileSize : 4083853312
ImagePath : D:\ISOs\windows10.iso
LogicalSectorSize : 2048
Number : 0
Size : 4083853312
StorageType : 1
PSComputerName :
You will see a banner notification at the right bottom corner of your screen:
You can also check from Windows Explorer that the disk is mounted.
In some cases, you want to mount on a remote system. The main way to execute remote commands is with PowerShell remoting using the Enter-PSSession or Invoke-Command cmdlets.
Note: Before you begin, make sure PSRemoting is already enabled in your environment.
$computerName = 'IT-PC02'
Invoke-Command -ComputerName $computerName -ScriptBlock {
Mount-DiskImage -ImagePath F:\Windows11.iso
}
To get more about the command, you can find help in the following code snippet:
Get-Help Mount-DiskImage
NAME
Mount-DiskImage
SYNOPSIS
Mounts a previously created disk image (virtual hard disk or ISO), making it appear as a normal disk.
SYNTAX
Mount-DiskImage [-ImagePath] <String[]> [-Access {Unknown | ReadWrite | ReadOnly}] [-AsJob] [-CimSession
<CimSession[]>] [-Confirm] [-NoDriveLetter] [-PassThru] [-StorageType {Unknown | ISO | VHD | VHDX | VHDSet}]
[-ThrottleLimit <Int32>] [-WhatIf] [<CommonParameters>]
Mount-DiskImage [-Access {Unknown | ReadWrite | ReadOnly}] [-AsJob] [-CimSession <CimSession[]>] [-Confirm]
-InputObject <CimInstance[]> [-NoDriveLetter] [-PassThru] [-ThrottleLimit <Int32>] [-WhatIf] [<CommonParameters>]
DESCRIPTION
The Mount-DiskImage cmdlet mounts a previously created disk image (virtual hard disk or ISO), making it appear as
a normal disk. This cmdlet requires the full path of the VHD or ISO file. If the file is already mounted, then the
cmdlet will display the following error.
-- `"The process cannot access the file because it is being used by another process."`
To mount a VHD file, administrator privileges is required. Administrator privileges are not needed to mount an ISO
file on Windows? 8. On Windows Server? 2012, only an administrator is allowed to mount or eject an ISO file.
To create and mount a VHD on a computer running Hyper-V, use the New-VHD and Mount-VHD cmdlets in the Hyper-V
module (which is included in Windows 8 and Windows Server 2012 but not enabled by default). Alternatively, open
Disk Management and then choose Create VHD from the Action menu.
RELATED LINKS
Online Version:
https://learn.microsoft.com/powershell/module/storage/mount-diskimage?view=windowsserver2022-ps&wt.mc_id=ps-gethelp
Dismount-DiskImage
Get-DiskImage
REMARKS
To see the examples, type: "get-help Mount-DiskImage -examples".
For more information, type: "get-help Mount-DiskImage -detailed".
For technical information, type: "get-help Mount-DiskImage -full".
For online help, type: "get-help Mount-DiskImage -online"
Unmount ISO file using PowerShell
The Dismount-DiskImage cmdlet dismounts a disk image (virtual hard disk or ISO) so that it can no longer be accessed as a disk. This cmdlet requires either the full image path of the ISO or VHD file, or the device path.
This example ejects an mounted ISO by specifying the image path at “D:\ISOs\windows10.iso”.
Dismount-DiskImage -ImagePath "D:\ISOs\windows10.iso"
Attached : False
BlockSize : 0
DevicePath :
FileSize : 4083853312
ImagePath : D:\ISOs\windows10.iso
LogicalSectorSize : 2048
Number :
Size : 4083853312
StorageType : 1
PSComputerName :
If you remember the drive letter, you can chain several commands to unmount the iso file. The below command will try to find the image path based on mounted drive-in drive E, then finally unmount it.
Get-Volume -DriveLetter 'E' | Get-DiskImage | Dismount-DiskImage
Conclusion
In conclusion, to mount and unmount ISO files in PowerShell we can use Mount-DiskImage and Dismount-DiskImage cmdlet respectively.