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"