How to List Files in an ISO Image Without Mounting It?

I’m working on a script to list the files in the root directory of an ISO image.

Currently, the script requires mounting the ISO to access and list the files, but I want to achieve this without mounting the ISO or relying on third-party tools.

By mounting i mean, not make them visible as disk letters, im querying multiple isos and them spam a lot of temp disks.

function Get-IsoContents {
    param (
        [string]$IsoPath
    )
    # Verify the file exists
    if (-not (Test-Path $IsoPath)) {
        Write-Error "ISO file not found: $IsoPath"
        return
    }
    try {
        # Mount the ISO image
        $mountResult = Mount-DiskImage -ImagePath $IsoPath -PassThru
        
        # Get the volume information
        $volume = $mountResult | Get-Volume
        
        # Check if volume was successfully retrieved
        if (-not $volume) {
            Write-Error "Could not retrieve volume information"
            return
        }
        
        # Get the drive letter
        $driveLetter = $volume.DriveLetter
        
        # Verify drive letter is not null or empty
        if ([string]::IsNullOrWhiteSpace($driveLetter)) {
            Write-Error "No drive letter assigned to the mounted ISO"
            return
        }
        
        # Construct full path and list contents
        $fullPath = $driveLetter + ":\"
        Get-ChildItem -Path $fullPath -Force | Select-Object -ExpandProperty Name
    }
    catch {
        Write-Error "Error accessing ISO contents: $_"
    }
    finally {
        # Ensure the ISO is dismounted
        if ($mountResult) {
            Dismount-DiskImage -ImagePath $IsoPath | Out-Null
        }
    }
}
# Usage example
Get-IsoContents -IsoPath "C:\Users\iso.iso"

Hi, welcome to the forum :wave:

Use Mount-DiskImage with the NoDriveLetter parameter.

$image = Mount-DiskImage -ImagePath <iso> -NoDriveLetter
$vol = $image | Get-Volume
Get-ChildItem -LiteralPath $vol.UniqueId

Hello, i’m trying to find a way that doesnt require mounting the iso, I’m querying multiple isos not a single one, even with -NoDriveLetter it still spams the tray icons.

This doesn’t spam anything

$Image = Mount-DiskImage -ImagePath <path.to.iso> -NoDriveLetter -StorageType ISO
New-PSDrive -Name MyISO -PSProvider Filesystem -Root (Get-Volume -DiskImage $Image).UniqueId

Get-ChildItem MyISO:\

Thanks, and how to dismount the iso?
I have tried:

$Image = Mount-DiskImage -ImagePath $IsoPath -NoDriveLetter -StorageType ISO
New-PSDrive -Name MyISO -PSProvider Filesystem -Root (Get-Volume -DiskImage $Image).UniqueId

Get-ChildItem MyISO:\

Get-DiskImage -ImagePath $IsoPath
Dismount-DiskImage -ImagePath $IsoPath -Confirm:$false

what happens after the Dismount-DiskImage?

That should work, but you need to remove the PSDrive first

$Image = Mount-DiskImage -ImagePath $IsoPath -NoDriveLetter -StorageType ISO
New-PSDrive -Name MyISO -PSProvider Filesystem -Root (Get-Volume -DiskImage $Image).UniqueId

Get-ChildItem MyISO:\

Get-DiskImage -ImagePath $IsoPath
Remove-PSDrive -Name MyISO
Dismount-DiskImage -ImagePath $IsoPath -Confirm:$false

Add in the Remove-PSDrive prior to the dismount and it works.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.