Forum Discussion
Newbie here...
- Nov 18, 2024
You can first mount the ISO and then connect a drive letter to this, and I wrote this script for that:
#Requires -RunAsAdministrator param ( [Parameter(Mandatory = $true)][String]$ISOFileName, [Parameter(Mandatory = $true)][String]$DriveLetter ) #Check if DriveLetter is in use if (Test-Path -LiteralPath "$($DriveLetter):") { Write-Warning ("Specified driveletter {0}: is in use, exiting..." -f $DriveLetter) return } #Check if $IsoFileName was already mounted if ((Get-DiskImage -ImagePath $ISOFileName).Attached) { Write-Warning ("ISO {0} already mounted, exiting..." -f $ISOFileName) return } #Mount first if (Test-Path -LiteralPath $ISOFileName) { try { $Mount = Mount-DiskImage -ImagePath $ISOFileName -NoDriveLetter -StorageType ISO -Access ReadOnly -ErrorAction Stop } catch { Write-Warning ("Error mounting {0}, exiting..." -f $ISOFileName) return } } #Assign driveletter try { mountvol.exe "$($DriveLetter):" $($mount | Get-Volume).UniqueId Write-Host ("Mounted {0} at {1}:" -f $ISOFileName, $DriveLetter) -ForegroundColor Green } catch { Write-Warning { "Error mounting {0} at {1}:, dismounting {2}" -f $ISOFileName, $DriveLetter, $ISOFileName } try { Dismount-DiskImage -ImagePath $ISOFileName -ErrorAction Stop Write-Host { "Dismounted {0}..." -f $ISOFileName } } catch { Write-Warning ("Error dismounting {0}, Check Diskmanagement" -f $ISOFileName) } }
Save the script to c:\scripts, as mount-iso.ps1, for example. Then run it as Administrator, as c:\scripts\mount-iso.ps1 -ISOFileName c:\data\iso\isofilename.iso -DriveLetter X to mount c:\data\iso\isofilename.iso as X:\
You can first mount the ISO and then connect a drive letter to this, and I wrote this script for that:
#Requires -RunAsAdministrator
param (
[Parameter(Mandatory = $true)][String]$ISOFileName,
[Parameter(Mandatory = $true)][String]$DriveLetter
)
#Check if DriveLetter is in use
if (Test-Path -LiteralPath "$($DriveLetter):") {
Write-Warning ("Specified driveletter {0}: is in use, exiting..." -f $DriveLetter)
return
}
#Check if $IsoFileName was already mounted
if ((Get-DiskImage -ImagePath $ISOFileName).Attached) {
Write-Warning ("ISO {0} already mounted, exiting..." -f $ISOFileName)
return
}
#Mount first
if (Test-Path -LiteralPath $ISOFileName) {
try {
$Mount = Mount-DiskImage -ImagePath $ISOFileName -NoDriveLetter -StorageType ISO -Access ReadOnly -ErrorAction Stop
}
catch {
Write-Warning ("Error mounting {0}, exiting..." -f $ISOFileName)
return
}
}
#Assign driveletter
try {
mountvol.exe "$($DriveLetter):" $($mount | Get-Volume).UniqueId
Write-Host ("Mounted {0} at {1}:" -f $ISOFileName, $DriveLetter) -ForegroundColor Green
}
catch {
Write-Warning { "Error mounting {0} at {1}:, dismounting {2}" -f $ISOFileName, $DriveLetter, $ISOFileName }
try {
Dismount-DiskImage -ImagePath $ISOFileName -ErrorAction Stop
Write-Host { "Dismounted {0}..." -f $ISOFileName }
}
catch {
Write-Warning ("Error dismounting {0}, Check Diskmanagement" -f $ISOFileName)
}
}
Save the script to c:\scripts, as mount-iso.ps1, for example. Then run it as Administrator, as c:\scripts\mount-iso.ps1 -ISOFileName c:\data\iso\isofilename.iso -DriveLetter X to mount c:\data\iso\isofilename.iso as X:\
Wow... very thorough script... more complex than I expected. I would've hope that it was easier... such as a single line command as:
Powershell -command "Mount-DiskImage -ImagePath ""c:\image\image.iso"" -DriveLetter F
Instead, there is no -DriveLetter parameter for Mount-DiskImage...
I am grateful for your assistance.
- Nov 19, 2024
It's a lot of error-handling, but yes 😅 The ISO is mounted by default, but if you want a different drive letter... Then you have to do more work 😅
Please mark my answer as Solution if it works for you to mark it as solved