# Hard‑coded paths $IsoPath = "C:\path\to\foo.iso" $MountPoint = "C:\readonlydir" # Normalize ISO path for comparison $isoFull = (Resolve-Path $IsoPath).Path # Check if ISO is already mounted $mounted = Get-DiskImage -ImagePath $isoFull -ErrorAction SilentlyContinue if ($mounted -and $mounted.Attached) { Write-Host "ISO is already mounted. Exiting." exit 0 } # Mount the ISO $diskImage = Mount-DiskImage -ImagePath $isoFull -PassThru # Wait for the system to assign a volume $vol = $null while ($vol -eq $null) { Start-Sleep -Milliseconds 200 $vol = Get-Volume -DiskImage $diskImage -ErrorAction SilentlyContinue } Write-Host "ISO mounted as volume: $($vol.DriveLetter):" # Ensure the mount point directory exists if (-not (Test-Path $MountPoint)) { New-Item -ItemType Directory -Path $MountPoint | Out-Null } # Convert drive letter to volume GUID path $volObj = Get-Volume -DriveLetter $vol.DriveLetter $guidPath = "\\?\Volume{$($volObj.Guid)}\" # Mount the volume into the directory mountvol $MountPoint $guidPath Write-Host "Mounted ISO volume at directory: $MountPoint"